Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
emoUS-public
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
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
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
general
dsml
emoUS-public
Commits
ebbdd47b
Commit
ebbdd47b
authored
2 years ago
by
blpeng
Browse files
Options
Downloads
Patches
Plain Diff
fix issue127: soloist import error.
parent
84251cfd
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
convlab/e2e/soloist/multiwoz/soloist.py
+1
-1
1 addition, 1 deletion
convlab/e2e/soloist/multiwoz/soloist.py
convlab/e2e/soloist/multiwoz/soloist_net.py
+48
-0
48 additions, 0 deletions
convlab/e2e/soloist/multiwoz/soloist_net.py
with
49 additions
and
1 deletion
convlab/e2e/soloist/multiwoz/soloist.py
+
1
−
1
View file @
ebbdd47b
...
...
@@ -10,7 +10,7 @@ from nltk.tokenize import word_tokenize
from
convlab.util.file_util
import
cached_path
from
convlab.e2e.soloist.multiwoz.config
import
global_config
as
cfg
from
convlab.e2e.soloist.multiwoz.soloist_net
import
SOLOIST
,
cuda_
from
convlab.e2e.soloist.multiwoz.soloist_net
import
SOLOIST
from
convlab.dialog_agent
import
Agent
from
utils
import
MultiWozReader
...
...
This diff is collapsed.
Click to expand it.
convlab/e2e/soloist/multiwoz/soloist_net.py
0 → 100644
+
48
−
0
View file @
ebbdd47b
import
logging
import
torch
from
transformers
import
(
AutoConfig
,
AutoModelForSeq2SeqLM
,
AutoTokenizer
)
from
convlab.e2e.soloist.multiwoz.config
import
global_config
as
cfg
logger
=
logging
.
getLogger
(
__name__
)
logging
.
basicConfig
(
format
=
"
%(asctime)s - %(levelname)s - %(name)s - %(message)s
"
,
datefmt
=
"
%m/%d/%Y %H:%M:%S
"
,
level
=
logging
.
INFO
,
)
def
cuda_
(
var
):
return
var
.
cuda
()
if
cfg
.
cuda
and
torch
.
cuda
.
is_available
()
else
var
def
tensor
(
var
):
return
cuda_
(
torch
.
tensor
(
var
))
class
SOLOIST
:
def
__init__
(
self
)
->
None
:
self
.
config
=
AutoConfig
.
from_pretrained
(
cfg
.
model_name_or_path
)
self
.
model
=
AutoModelForSeq2SeqLM
.
from_pretrained
(
cfg
.
model_name_or_path
,
config
=
self
.
config
)
self
.
tokenizer
=
AutoTokenizer
.
from_pretrained
(
'
t5-base
'
)
print
(
'
model loaded!
'
)
self
.
model
=
self
.
model
.
cuda
()
if
torch
.
cuda
.
is_available
()
else
self
.
model
def
generate
(
self
,
inputs
):
self
.
model
.
eval
()
inputs
=
self
.
tokenizer
([
inputs
])
input_ids
=
tensor
(
inputs
[
'
input_ids
'
])
generated_tokens
=
self
.
model
.
generate
(
input_ids
=
input_ids
,
max_length
=
cfg
.
max_length
,
top_p
=
cfg
.
top_p
)
decoded_preds
=
self
.
tokenizer
.
batch_decode
(
generated_tokens
,
skip_special_tokens
=
True
)
return
decoded_preds
[
0
]
\ 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