Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

update for new AllenNlpTestCase #45

Merged
merged 3 commits into from
May 7, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
git+https://github.com/allenai/allennlp.git@master
git+https://github.com/epwalsh/allennlp.git@test-case
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Temporary change to make sure tests will pass


# For RC models
word2number>=1.1
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def requirement_is_allennlp(req: str) -> bool:
return True
if re.match(r"^allennlp[>=<]", req):
return True
if re.match(r"^(git\+)?(https|ssh)://(git@)?github\.com/allenai/allennlp\.git", req):
if re.match(r"^(git\+)?(https|ssh)://(git@)?github\.com/.*/allennlp\.git", req):
return True
return False

Expand Down
6 changes: 3 additions & 3 deletions tests/coref/coref_model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@


class CorefTest(ModelTestCase):
def setUp(self):
super().setUp()
def setup_method(self):
super().setup_method()
self.set_up_model(
FIXTURES_ROOT / "coref" / "experiment.json",
FIXTURES_ROOT / "coref" / "coref.gold_conll",
Expand All @@ -31,7 +31,7 @@ def _test_coref_model_can_train_save_and_load(
# fmt: on
self.ensure_model_can_train_save_and_load(self.param_file, overrides=overrides)
self.tearDown()
self.setUp()
self.setup_method()

def test_coref_bert_model_can_train_save_and_load(self):
self.set_up_model(
Expand Down
8 changes: 4 additions & 4 deletions tests/lm/bidirectional_lm_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@


class TestBidirectionalLanguageModel(ModelTestCase):
def setUp(self):
super().setUp()
def setup_method(self):
super().setup_method()

self.expected_embedding_shape = (2, 8, 14)

Expand Down Expand Up @@ -47,8 +47,8 @@ def test_forward_pass_runs_correctly(self):


class TestBidirectionalLanguageModelUnsampled(TestBidirectionalLanguageModel):
def setUp(self):
super().setUp()
def setup_method(self):
super().setup_method()
self.set_up_model(
FIXTURES_ROOT / "lm" / "language_model" / "experiment_bidirectional_unsampled.jsonnet",
FIXTURES_ROOT / "lm" / "language_model" / "sentences.txt",
Expand Down
8 changes: 4 additions & 4 deletions tests/lm/bidirectional_lm_token_embedder_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@


class TestBidirectionalLanguageModelTokenEmbedder(TestLanguageModelTokenEmbedder):
def setUp(self):
super().setUp()
def setup_method(self):
super().setup_method()
self.set_up_model(
FIXTURES_ROOT
/ "lm"
Expand All @@ -15,8 +15,8 @@ def setUp(self):


class TestBidirectionalLanguageModelTokenEmbedderWithoutBosEos(TestLanguageModelTokenEmbedder):
def setUp(self):
super().setUp()
def setup_method(self):
super().setup_method()
self.set_up_model(
FIXTURES_ROOT
/ "lm"
Expand Down
4 changes: 2 additions & 2 deletions tests/lm/composed_seq2seq_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@


class ComposedSeq2SeqTest(ModelTestCase):
def setUp(self):
super().setUp()
def setup_method(self):
super().setup_method()
self.set_up_model(
FIXTURES_ROOT / "seq2seq" / "composed" / "experiment.json",
FIXTURES_ROOT / "seq2seq" / "seq2seq_copy.tsv",
Expand Down
4 changes: 2 additions & 2 deletions tests/lm/copynet_seq2seq_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@


class CopyNetTest(ModelTestCase):
def setUp(self):
super().setUp()
def setup_method(self):
super().setup_method()
self.set_up_model(
FIXTURES_ROOT / "seq2seq" / "copynet" / "experiment.json",
FIXTURES_ROOT / "seq2seq" / "copynet" / "data" / "copyover.tsv",
Expand Down
24 changes: 12 additions & 12 deletions tests/lm/language_model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@


class TestUnidirectionalLanguageModel(ModelTestCase):
def setUp(self):
super().setUp()
def setup_method(self):
super().setup_method()

self.expected_embedding_shape = (2, 8, 7)
self.bidirectional = False
Expand Down Expand Up @@ -70,17 +70,17 @@ def test_language_model_forward_on_instances(self):


class TestUnidirectionalLanguageModelUnsampled(TestUnidirectionalLanguageModel):
def setUp(self):
super().setUp()
def setup_method(self):
super().setup_method()
self.set_up_model(
FIXTURES_ROOT / "lm" / "language_model" / "experiment_unidirectional_unsampled.jsonnet",
FIXTURES_ROOT / "lm" / "language_model" / "sentences.txt",
)


class TestUnidirectionalLanguageModelTransformer(TestUnidirectionalLanguageModel):
def setUp(self):
super().setUp()
def setup_method(self):
super().setup_method()

self.expected_embedding_shape = (2, 8, 16)

Expand All @@ -105,8 +105,8 @@ def test_unidirectional_language_model_can_train_save_and_load(self):


class TestBidirectionalLanguageModel(TestUnidirectionalLanguageModel):
def setUp(self):
super().setUp()
def setup_method(self):
super().setup_method()

self.expected_embedding_shape = (2, 8, 14)
self.bidirectional = True
Expand All @@ -119,17 +119,17 @@ def setUp(self):


class TestBidirectionalLanguageModelUnsampled(TestBidirectionalLanguageModel):
def setUp(self):
super().setUp()
def setup_method(self):
super().setup_method()
self.set_up_model(
FIXTURES_ROOT / "lm" / "language_model" / "experiment_unsampled.jsonnet",
FIXTURES_ROOT / "lm" / "language_model" / "sentences.txt",
)


class TestBidirectionalLanguageModelTransformer(TestBidirectionalLanguageModel):
def setUp(self):
super().setUp()
def setup_method(self):
super().setup_method()

self.expected_embedding_shape = (2, 8, 32)

Expand Down
8 changes: 4 additions & 4 deletions tests/lm/language_model_token_embedder_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@


class TestLanguageModelTokenEmbedder(ModelTestCase):
def setUp(self):
super().setUp()
def setup_method(self):
super().setup_method()
self.set_up_model(
FIXTURES_ROOT / "lm" / "language_model" / "characters_token_embedder.json",
FIXTURES_ROOT / "lm" / "conll2003.txt",
Expand All @@ -31,8 +31,8 @@ def test_tagger_with_language_model_token_embedder_forward_pass_runs_correctly(s


class TestLanguageModelTokenEmbedderWithoutBosEos(TestLanguageModelTokenEmbedder):
def setUp(self):
super().setUp()
def setup_method(self):
super().setup_method()
self.set_up_model(
FIXTURES_ROOT
/ "lm"
Expand Down
4 changes: 2 additions & 2 deletions tests/lm/masked_language_model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@


class TestMaskedLanguageModel(ModelTestCase):
def setUp(self):
super().setUp()
def setup_method(self):
super().setup_method()
self.set_up_model(
FIXTURES_ROOT / "lm" / "masked_language_model" / "experiment.json",
FIXTURES_ROOT / "lm" / "language_model" / "sentences.txt",
Expand Down
4 changes: 2 additions & 2 deletions tests/lm/next_token_lm_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@


class TestNextTokenLanguageModel(ModelTestCase):
def setUp(self):
super().setUp()
def setup_method(self):
super().setup_method()
self.set_up_model(
FIXTURES_ROOT / "lm" / "next_token_lm" / "experiment.json",
FIXTURES_ROOT / "lm" / "language_model" / "sentences.txt",
Expand Down
12 changes: 5 additions & 7 deletions tests/lm/simple_language_modeling_reader_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_text_to_instance(self):

instance = dataset.text_to_instance("The only sentence.")
text = [t.text for t in cast(TextField, instance.fields["source"]).tokens]
self.assertEqual(text, ["<S>", "The", "only", "sentence", ".", "</S>"])
assert text == ["<S>", "The", "only", "sentence", ".", "</S>"]

def test_read_single_sentence(self):
prefix = os.path.join(self.FIXTURES, "single_sentence.txt")
Expand All @@ -27,19 +27,17 @@ def test_read_single_sentence(self):
batch = None
for batch in dataset.read(prefix):
break
self.assertEqual(
sorted(list(expected_batch.fields.keys())), sorted(list(batch.fields.keys()))
)
assert sorted(list(expected_batch.fields.keys())) == sorted(list(batch.fields.keys()))
for k in expected_batch.fields.keys():
self.assertTrue(str(expected_batch.fields[k]) == str(batch.fields[k]))
assert str(expected_batch.fields[k]) == str(batch.fields[k])

def test_read_multiple_sentences(self):
prefix = os.path.join(self.FIXTURES, "shards/shard0")
dataset = SimpleLanguageModelingDatasetReader()
k = -1
for k, _ in enumerate(dataset.read(prefix)):
pass
self.assertEqual(k, 99)
assert k == 99

def test_max_sequence_length(self):
prefix = os.path.join(self.FIXTURES, "shards/shard0")
Expand All @@ -49,4 +47,4 @@ def test_max_sequence_length(self):
k = -1
for k, _ in enumerate(dataset.read(prefix)):
pass
self.assertEqual(k, 7)
assert k == 7
4 changes: 2 additions & 2 deletions tests/lm/simple_seq2seq_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@


class SimpleSeq2SeqTest(ModelTestCase):
def setUp(self):
super().setUp()
def setup_method(self):
super().setup_method()
self.set_up_model(
FIXTURES_ROOT / "seq2seq" / "simple" / "experiment.json",
FIXTURES_ROOT / "seq2seq" / "seq2seq_copy.tsv",
Expand Down
11 changes: 7 additions & 4 deletions tests/ner/ccgbank_reader_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ def test_vocab_from_instances_namespaces(self):
instances = ensure_list(reader.read(FIXTURES_ROOT / "ner" / "ccgbank.txt"))
# check that we didn't clobber the labels namespace
vocab = Vocabulary.from_instances(instances)
self.assertSetEqual(
set(vocab._token_to_index.keys()),
{"tokens", "labels", "modified_pos_tags", "original_pos_tags", "predicate_arg_tags"},
)
assert set(vocab._token_to_index.keys()) == {
"tokens",
"labels",
"modified_pos_tags",
"original_pos_tags",
"predicate_arg_tags",
}
4 changes: 2 additions & 2 deletions tests/ner/crf_tagger_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@


class CrfTaggerTest(ModelTestCase):
def setUp(self):
super().setUp()
def setup_method(self):
super().setup_method()
self.set_up_model(
FIXTURES_ROOT / "ner" / "crf_tagger" / "experiment.json",
FIXTURES_ROOT / "ner" / "conll2003.txt",
Expand Down
4 changes: 2 additions & 2 deletions tests/nli/bimpm_model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@


class TestBiMPM(ModelTestCase):
def setUp(self):
super().setUp()
def setup_method(self):
super().setup_method()
self.set_up_model(
FIXTURES_ROOT / "nli" / "bimpm" / "experiment.json",
FIXTURES_ROOT / "nli" / "quora_paraphrase.tsv",
Expand Down
4 changes: 2 additions & 2 deletions tests/nli/decomposable_attention_model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@


class TestDecomposableAttention(ModelTestCase):
def setUp(self):
super().setUp()
def setup_method(self):
super().setup_method()
self.set_up_model(
FIXTURES_ROOT / "nli" / "decomposable_attention" / "experiment.json",
FIXTURES_ROOT / "nli" / "snli.jsonl",
Expand Down
4 changes: 2 additions & 2 deletions tests/nli/esim_model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@


class TestESIM(ModelTestCase):
def setUp(self):
super().setUp()
def setup_method(self):
super().setup_method()
self.set_up_model(
FIXTURES_ROOT / "nli" / "esim" / "experiment.json",
FIXTURES_ROOT / "nli" / "snli.jsonl",
Expand Down
4 changes: 2 additions & 2 deletions tests/rc/bidaf/bidaf_ensemble_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@


class BidafEnsembleTest(ModelTestCase):
def setUp(self):
super().setUp()
def setup_method(self):
super().setup_method()
self.set_up_model(
FIXTURES_ROOT / "rc" / "bidaf" / "experiment.json", FIXTURES_ROOT / "rc" / "squad.json"
)
Expand Down
4 changes: 2 additions & 2 deletions tests/rc/bidaf/bidaf_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@


class BidirectionalAttentionFlowTest(ModelTestCase):
def setUp(self):
super().setUp()
def setup_method(self):
super().setup_method()
self.set_up_model(
FIXTURES_ROOT / "rc" / "bidaf" / "experiment.json", FIXTURES_ROOT / "rc" / "squad.json"
)
Expand Down
4 changes: 2 additions & 2 deletions tests/rc/dialog_qa/dialog_qa_model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@


class DialogQATest(ModelTestCase):
def setUp(self):
super().setUp()
def setup_method(self):
super().setup_method()
self.set_up_model(
FIXTURES_ROOT / "rc" / "dialog_qa" / "experiment.json",
FIXTURES_ROOT / "rc" / "dialog_qa" / "quac_sample.json",
Expand Down
4 changes: 2 additions & 2 deletions tests/rc/qanet/naqanet_model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@


class NumericallyAugmentedQaNetTest(ModelTestCase):
def setUp(self):
super().setUp()
def setup_method(self):
super().setup_method()
self.set_up_model(
FIXTURES_ROOT / "rc" / "naqanet" / "experiment.json", FIXTURES_ROOT / "rc" / "drop.json"
)
Expand Down
4 changes: 2 additions & 2 deletions tests/rc/qanet/qanet_model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@


class QaNetTest(ModelTestCase):
def setUp(self):
super().setUp()
def setup_method(self):
super().setup_method()
self.set_up_model(
FIXTURES_ROOT / "rc" / "qanet" / "experiment.json", FIXTURES_ROOT / "rc" / "squad.json"
)
Expand Down
4 changes: 2 additions & 2 deletions tests/rc/transformer_qa/transformer_qa_model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@


class TransformerQaTest(ModelTestCase):
def setUp(self):
super().setUp()
def setup_method(self):
super().setup_method()
self.set_up_model(
FIXTURES_ROOT / "rc" / "transformer_qa" / "experiment.jsonnet",
FIXTURES_ROOT / "rc" / "squad.json",
Expand Down
4 changes: 2 additions & 2 deletions tests/rc/transformer_qa/transformer_qa_predictor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@


class TestTransformerQAPredictor(AllenNlpTestCase):
def setUp(self):
super().setUp()
def setup_method(self):
super().setup_method()
self.reader = TransformerSquadReader(length_limit=50, stride=10)
self.vocab = Vocabulary()
self.model = TransformerQA(self.vocab)
Expand Down
Loading