Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
winer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Redmine
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nlpworkers
winer
Commits
44b886c3
Commit
44b886c3
authored
11 months ago
by
Marek Maziarz
Browse files
Options
Downloads
Patches
Plain Diff
doctring added to pack_sentences_to_max_tokens method
parent
ec05cf26
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#19505
failed
11 months ago
Stage: check_style
Stage: build_develop
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/winer_worker.py
+20
-2
20 additions, 2 deletions
src/winer_worker.py
with
20 additions
and
2 deletions
src/winer_worker.py
+
20
−
2
View file @
44b886c3
...
@@ -34,6 +34,25 @@ class WinerWorker(nlp_ws.NLPWorker):
...
@@ -34,6 +34,25 @@ class WinerWorker(nlp_ws.NLPWorker):
@staticmethod
@staticmethod
def
pack_sentences_to_max_tokens
(
plain_inputs
,
tokenized_inputs
,
sent_starts
,
max_tokens
=
512
):
def
pack_sentences_to_max_tokens
(
plain_inputs
,
tokenized_inputs
,
sent_starts
,
max_tokens
=
512
):
"""
Pack sentences into chunks, ensuring that the token count per chunk does not exceed a given maximum.
This method takes in plain text sentences, their tokenized versions, and sentence start indices,
and it creates batches of sentences such that the total token count per batch does not exceed the
specified max_tokens limit.
Args:
plain_inputs (list): List of plain text sentences.
tokenized_inputs (list): List of tokenized versions of the sentences.
sent_starts (list): List of sentence start indices.
max_tokens (int, optional): The maximum number of tokens allowed per chunk. Defaults to 512.
Returns:
tuple:
- packed_plain_inputs (list): List of packed plain text sentences, where each element is a chunk of sentences.
- packed_tokenized_inputs (list): List of packed tokenized inputs corresponding to the plain text chunks.
- packed_sent_starts (list): List of sentence start indices for each chunk.
"""
packed_plain_inputs
=
[]
packed_plain_inputs
=
[]
packed_tokenized_inputs
=
[]
packed_tokenized_inputs
=
[]
packed_sent_starts
=
[]
packed_sent_starts
=
[]
...
@@ -87,7 +106,6 @@ class WinerWorker(nlp_ws.NLPWorker):
...
@@ -87,7 +106,6 @@ class WinerWorker(nlp_ws.NLPWorker):
worker will store result.
worker will store result.
:type output_path: str
:type output_path: str
"""
"""
# Read inputs and open output
# Read inputs and open output
F_ASCII
=
task_options
.
get
(
"
ensure_ascii
"
,
False
)
F_ASCII
=
task_options
.
get
(
"
ensure_ascii
"
,
False
)
with
clarin_json
.
open
(
output_path
,
"
w
"
,
ensure_ascii
=
F_ASCII
)
as
fout
:
with
clarin_json
.
open
(
output_path
,
"
w
"
,
ensure_ascii
=
F_ASCII
)
as
fout
:
...
@@ -98,7 +116,7 @@ class WinerWorker(nlp_ws.NLPWorker):
...
@@ -98,7 +116,7 @@ class WinerWorker(nlp_ws.NLPWorker):
get_sentences_from_document
(
document
)
get_sentences_from_document
(
document
)
packed_plain_texts
,
packed_tokenized_inputs
,
packed_sent_starts
=
pack_sentences_to_max_tokens
(
packed_plain_texts
,
packed_tokenized_inputs
,
packed_sent_starts
=
pack_sentences_to_max_tokens
(
plain_inputs
,
tokenized_inputs
,
sent_starts
,
max_tokens
=
51
2
plain_inputs
,
tokenized_inputs
,
sent_starts
,
max_tokens
=
51
0
)
)
# Process data
# Process data
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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