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
15f4ca6b
Commit
15f4ca6b
authored
2 years ago
by
Maja Jabłońska
Browse files
Options
Downloads
Patches
Plain Diff
Add a TokenCountBatchSamplerTest
parent
7c100666
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/fields/test_samplers.py
+31
-0
31 additions, 0 deletions
tests/data/fields/test_samplers.py
with
31 additions
and
0 deletions
tests/data/fields/test_samplers.py
0 → 100644
+
31
−
0
View file @
15f4ca6b
"""
Sampler tests.
"""
import
unittest
from
combo.data
import
TokenCountBatchSampler
,
Instance
from
combo.data.fields.text_field
import
TextField
from
combo.data.tokenizers
import
TokenizerToken
class
TokenCountBatchSamplerTest
(
unittest
.
TestCase
):
def
setUp
(
self
)
->
None
:
self
.
dataset
=
[]
self
.
sentences
=
[
"
First sentence makes full batch.
"
,
"
Short
"
,
"
This ends first batch
"
]
for
sentence
in
self
.
sentences
:
tokens
=
[
TokenizerToken
(
t
)
for
t
in
sentence
.
split
()]
text_field
=
TextField
(
tokens
,
{})
self
.
dataset
.
append
(
Instance
({
"
sentence
"
:
text_field
}))
def
test_batches
(
self
):
# given
sampler
=
TokenCountBatchSampler
(
self
.
dataset
,
word_batch_size
=
2
,
shuffle_dataset
=
False
)
# when
length
=
len
(
sampler
)
values
=
list
(
sampler
)
# then
self
.
assertEqual
(
2
,
length
)
# sort by lengths + word_batch_size makes 1, 2 first batch
self
.
assertListEqual
([[
1
,
2
],
[
0
]],
values
)
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