Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
combo
Manage
Activity
Members
Labels
Plan
Issues
20
Issue boards
Milestones
Wiki
Redmine
Code
Merge requests
2
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Syntactic Tools
combo
Commits
e391d48d
Commit
e391d48d
authored
2 years ago
by
Maja Jabłońska
Browse files
Options
Downloads
Patches
Plain Diff
Add itos and stoi tests for Vocabulary
parent
e3dc6fdf
1 merge request
!46
Merge COMBO 3.0 into master
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/data/test_vocabulary.py
+41
-0
41 additions, 0 deletions
tests/data/test_vocabulary.py
with
41 additions
and
0 deletions
tests/data/test_vocabulary.py
+
41
−
0
View file @
e391d48d
...
@@ -59,6 +59,29 @@ class VocabularyTest(unittest.TestCase):
...
@@ -59,6 +59,29 @@ class VocabularyTest(unittest.TestCase):
self
.
assertEqual
(
v
.
get_token_from_index
(
2
,
'
padded_example
'
),
'
test_token1
'
)
self
.
assertEqual
(
v
.
get_token_from_index
(
2
,
'
padded_example
'
),
'
test_token1
'
)
self
.
assertEqual
(
v
.
get_token_from_index
(
3
,
'
padded_example
'
),
'
test_token2
'
)
self
.
assertEqual
(
v
.
get_token_from_index
(
3
,
'
padded_example
'
),
'
test_token2
'
)
def
test_add_tokens_to_padded_namespace_correct_index_to_token_dict
(
self
):
padded_namespaces
=
[
'
padded_example
'
]
non_padded_namespaces
=
[
'
non_padded_example
'
]
v
=
Vocabulary
(
non_padded_namespaces
=
non_padded_namespaces
)
v
.
add_tokens_to_namespace
([
'
test_token1
'
,
'
test_token2
'
],
'
padded_example
'
)
self
.
assertEqual
(
v
.
get_index_to_token_vocabulary
(
'
padded_example
'
),
{
0
:
'
@@PADDING@@
'
,
1
:
'
@@UNKNOWN@@
'
,
2
:
'
test_token1
'
,
3
:
'
test_token2
'
})
def
test_add_tokens_to_padded_namespace_correct_token_to_index_dict
(
self
):
padded_namespaces
=
[
'
padded_example
'
]
non_padded_namespaces
=
[
'
non_padded_example
'
]
v
=
Vocabulary
(
non_padded_namespaces
=
non_padded_namespaces
)
v
.
add_tokens_to_namespace
([
'
test_token1
'
,
'
test_token2
'
],
'
padded_example
'
)
self
.
assertEqual
(
v
.
get_token_to_index_vocabulary
(
'
padded_example
'
),
{
'
@@PADDING@@
'
:
0
,
'
@@UNKNOWN@@
'
:
1
,
'
test_token1
'
:
2
,
'
test_token2
'
:
3
})
def
test_add_token_to_non_padded_namespace_correct_vocab_size
(
self
):
def
test_add_token_to_non_padded_namespace_correct_vocab_size
(
self
):
padded_namespaces
=
[
'
padded_example
'
]
padded_namespaces
=
[
'
padded_example
'
]
non_padded_namespaces
=
[
'
non_padded_example
'
]
non_padded_namespaces
=
[
'
non_padded_example
'
]
...
@@ -103,6 +126,24 @@ class VocabularyTest(unittest.TestCase):
...
@@ -103,6 +126,24 @@ class VocabularyTest(unittest.TestCase):
self
.
assertEqual
(
v
.
get_token_from_index
(
0
,
'
non_padded_example
'
),
'
test_token1
'
)
self
.
assertEqual
(
v
.
get_token_from_index
(
0
,
'
non_padded_example
'
),
'
test_token1
'
)
self
.
assertEqual
(
v
.
get_token_from_index
(
1
,
'
non_padded_example
'
),
'
test_token2
'
)
self
.
assertEqual
(
v
.
get_token_from_index
(
1
,
'
non_padded_example
'
),
'
test_token2
'
)
def
test_add_tokens_to_non_padded_namespace_correct_index_to_token_dict
(
self
):
padded_namespaces
=
[
'
padded_example
'
]
non_padded_namespaces
=
[
'
non_padded_example
'
]
v
=
Vocabulary
(
non_padded_namespaces
=
non_padded_namespaces
)
v
.
add_tokens_to_namespace
([
'
test_token1
'
,
'
test_token2
'
],
'
non_padded_example
'
)
self
.
assertEqual
(
v
.
get_index_to_token_vocabulary
(
'
non_padded_example
'
),
{
0
:
'
test_token1
'
,
1
:
'
test_token2
'
})
def
test_add_tokens_to_non_padded_namespace_correct_token_to_index_dict
(
self
):
padded_namespaces
=
[
'
padded_example
'
]
non_padded_namespaces
=
[
'
non_padded_example
'
]
v
=
Vocabulary
(
non_padded_namespaces
=
non_padded_namespaces
)
v
.
add_tokens_to_namespace
([
'
test_token1
'
,
'
test_token2
'
],
'
non_padded_example
'
)
self
.
assertEqual
(
v
.
get_token_to_index_vocabulary
(
'
non_padded_example
'
),
{
'
test_token1
'
:
0
,
'
test_token2
'
:
1
})
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
unittest
.
main
()
unittest
.
main
()
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment