2020-10-30 18:06:02 +01:00
|
|
|
import pytest
|
2022-01-04 18:34:16 +01:00
|
|
|
from pathlib import Path
|
2020-10-30 18:06:02 +01:00
|
|
|
|
2021-10-29 13:52:28 +05:30
|
|
|
from haystack.utils.preprocessing import convert_files_to_dicts, tika_convert_files_to_dicts
|
|
|
|
from haystack.utils.cleaning import clean_wiki_text
|
2022-01-04 18:34:16 +01:00
|
|
|
from haystack.utils.augment_squad import augment_squad
|
|
|
|
from haystack.utils.squad_data import SquadData
|
2020-10-01 14:47:45 +02:00
|
|
|
|
2021-10-29 13:52:28 +05:30
|
|
|
def test_convert_files_to_dicts():
|
2021-10-25 15:50:23 +02:00
|
|
|
documents = convert_files_to_dicts(dir_path="samples", clean_func=clean_wiki_text, split_paragraphs=True)
|
2020-10-01 14:47:45 +02:00
|
|
|
assert documents and len(documents) > 0
|
|
|
|
|
|
|
|
|
2020-10-30 18:06:02 +01:00
|
|
|
@pytest.mark.tika
|
2021-10-29 13:52:28 +05:30
|
|
|
def test_tika_convert_files_to_dicts():
|
2021-10-25 15:50:23 +02:00
|
|
|
documents = tika_convert_files_to_dicts(dir_path="samples", clean_func=clean_wiki_text, split_paragraphs=True)
|
2020-10-01 14:47:45 +02:00
|
|
|
assert documents and len(documents) > 0
|
|
|
|
|
2022-01-04 18:34:16 +01:00
|
|
|
def test_squad_augmentation():
|
|
|
|
input_ = Path("samples/squad/tiny.json")
|
|
|
|
output = Path("samples/squad/tiny_augmented.json")
|
|
|
|
glove_path = Path("samples/glove/tiny.txt") # dummy glove file, will not even be use when augmenting tiny.json
|
|
|
|
multiplication_factor = 5
|
2022-01-20 12:18:32 +01:00
|
|
|
augment_squad(model="distilbert-base-uncased", tokenizer="distilbert-base-uncased", squad_path=input_, output_path=output,
|
|
|
|
glove_path=glove_path, multiplication_factor=multiplication_factor)
|
2022-01-04 18:34:16 +01:00
|
|
|
original_squad = SquadData.from_file(input_)
|
|
|
|
augmented_squad = SquadData.from_file(output)
|
2022-01-20 12:18:32 +01:00
|
|
|
assert original_squad.count(unit="paragraph") == augmented_squad.count(unit="paragraph") * multiplication_factor
|