Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SwissArmyTransformer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
MachineLearning
thukeg
SwissArmyTransformer
Commits
21ce004a
Commit
21ce004a
authored
3 years ago
by
minkowski0125
Browse files
Options
Downloads
Patches
Plain Diff
add base tokenizer
parent
5de0e2c2
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
SwissArmyTransformer/tokenization/base_tokenizer.py
+53
-0
53 additions, 0 deletions
SwissArmyTransformer/tokenization/base_tokenizer.py
SwissArmyTransformer/tokenization/utils.py
+15
-0
15 additions, 0 deletions
SwissArmyTransformer/tokenization/utils.py
with
68 additions
and
0 deletions
SwissArmyTransformer/tokenization/base_tokenizer.py
0 → 100644
+
53
−
0
View file @
21ce004a
import
os
from
.utils
import
*
class
BaseTokenizer
:
def
__init__
(
self
,
**
kwargs
):
pass
def
__call__
(
self
,
text
,
**
kwargs
):
"""
run preprocessing and encode text as Ids
"""
return
self
.
EncodeAsIds
(
text
,
**
kwargs
)
def
__len__
(
self
):
"""
total number of tokens
"""
return
self
.
num_tokens
def
__repr__
(
self
):
"""
info interpretation for tokenizer
"""
return
"
Base Tokenizer for SAT
"
@property
def
command_tokens
(
self
):
"""
get command tokens of the tokenizer
"""
return
None
@property
def
num_tokens
(
self
):
"""
get total number of tokens
"""
return
0
def
from_pretrained
(
self
,
**
kwargs
):
"""
load tokenizer params from pretrained
"""
pass
def
EncodeAsIds
(
self
,
text
,
**
kwargs
):
"""
encode to ids by tokenizer
"""
raise
NotImplementedError
def
EncodeAsTokens
(
self
,
text
,
**
kwargs
):
"""
encode to tokens by tokenizer
"""
raise
NotImplementedError
def
DecodeIds
(
self
,
ids
,
**
kwargs
):
"""
decode ids to original form by tokenizer
"""
raise
NotImplementedError
def
DecodeTokens
(
self
,
tokens
,
**
kwargs
):
"""
decode tokens to original form by tokenizer
"""
raise
NotImplementedError
\ No newline at end of file
This diff is collapsed.
Click to expand it.
SwissArmyTransformer/tokenization/utils.py
0 → 100644
+
15
−
0
View file @
21ce004a
import
torch
import
numpy
as
np
import
tensorflow
as
tf
def
_is_list
(
x
):
return
isinstance
(
x
,
list
)
def
_is_numpy
(
x
):
return
isinstance
(
x
,
np
.
ndarray
)
def
_is_torch
(
x
):
return
isinstance
(
x
,
torch
.
Tensor
)
def
_is_tensorflow
(
x
):
return
isinstance
(
x
,
tf
.
Tensor
)
\ No newline at end of file
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