Текстовый классификатор Fastai: пакетный прогноз на невидимые данные - PullRequest
0 голосов
/ 26 февраля 2019

Я работаю с текстовым классификатором Фастая (https://docs.fast.ai/text.html).). В настоящее время я прогнозирую настроение (положительное или отрицательное) невидимых фраз следующим образом:

def _unpack_prediction(self, text) -> Tuple[bool, float]:
    out = self._model.predict(text)
    return str(out[0]) == "positive", max(out[2][0].item(), out[2][1].item())

def example(self, messages: Sequence[str]):
    results = map(self._unpack_prediction, messages)
    for phrase, out in zip(messages, results):
        print(f"{phrase[:100]}...[{'pos' if out[0] else 'neg'}] - [{out[1]:.2f}]")

Приведенный список фраз:

("I love this movie",
  "The actors are good, but this movie is definitely stupid",
  "There is no plot at all!!! Just special effects ")

Результат:

I love this movie...[pos] - [1.00]
The actors are good, but this movie is definitely stupid...[neg] - [0.96]
There is no plot at all!!! Just special effects ...[neg] - [0.95]

Однако последовательное применение прогноза к фразам довольно медленное.

Есть ли способ применить пакетное прогнозирование с помощью библиотеки fastaiбез создания тестового набора данных?

1 Ответ

0 голосов
/ 11 мая 2019

Вы, безусловно, можете.Вот пример кода для этого

test_df = pd.read_csv(path_to_test_csv_file)
learn.data.add_test(test_df[target_col_name])
prob_preds = learn.get_preds(ds_type=DatasetType.Test, ordered=True)

...