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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
general
dsml
emoUS-public
Commits
58f9a0d4
Commit
58f9a0d4
authored
Dec 13, 2022
by
zqwerty
Browse files
Options
Downloads
Patches
Plain Diff
update nlu interface: auto preprocess for jointbert; transform da output for t5nlu
parent
bfb44786
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/base_models/t5/nlu/nlu.py
+7
-4
7 additions, 4 deletions
convlab/base_models/t5/nlu/nlu.py
convlab/nlu/jointBERT/unified_datasets/nlu.py
+4
-1
4 additions, 1 deletion
convlab/nlu/jointBERT/unified_datasets/nlu.py
with
11 additions
and
5 deletions
convlab/base_models/t5/nlu/nlu.py
+
7
−
4
View file @
58f9a0d4
import
logging
g
import
logging
import
torch
import
torch
from
transformers
import
AutoTokenizer
,
AutoModelForSeq2SeqLM
,
AutoConfig
from
transformers
import
AutoTokenizer
,
AutoModelForSeq2SeqLM
,
AutoConfig
from
convlab.nlu.nlu
import
NLU
from
convlab.nlu.nlu
import
NLU
...
@@ -38,8 +38,11 @@ class T5NLU(NLU):
...
@@ -38,8 +38,11 @@ class T5NLU(NLU):
# print(output_seq)
# print(output_seq)
output_seq
=
self
.
tokenizer
.
decode
(
output_seq
[
0
],
skip_special_tokens
=
True
)
output_seq
=
self
.
tokenizer
.
decode
(
output_seq
[
0
],
skip_special_tokens
=
True
)
# print(output_seq)
# print(output_seq)
dialogue_acts
=
deserialize_dialogue_acts
(
output_seq
.
strip
())
das
=
deserialize_dialogue_acts
(
output_seq
.
strip
())
return
dialogue_acts
dialog_act
=
[]
for
da
in
das
:
dialog_act
.
append
([
da
[
'
intent
'
],
da
[
'
domain
'
],
da
[
'
slot
'
],
da
.
get
(
'
value
'
,
''
)])
return
dialog_act
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
...
@@ -67,7 +70,7 @@ if __name__ == '__main__':
...
@@ -67,7 +70,7 @@ if __name__ == '__main__':
"
I am not sure of the type of food but could you please check again and see if you can find it? Thank you.
"
,
"
I am not sure of the type of food but could you please check again and see if you can find it? Thank you.
"
,
"
Could you double check that you
'
ve spelled the name correctly? The closest I can find is Nandos.
"
]
"
Could you double check that you
'
ve spelled the name correctly? The closest I can find is Nandos.
"
]
]
]
nlu
=
T5NLU
(
speaker
=
'
user
'
,
context_window_size
=
3
,
model_name_or_path
=
'
output/
nlu
/
multiwoz21
/user/context_3
'
)
nlu
=
T5NLU
(
speaker
=
'
user
'
,
context_window_size
=
0
,
model_name_or_path
=
'
ConvLab/t5-small-
nlu
-
multiwoz21
'
)
for
text
,
context
in
zip
(
texts
,
contexts
):
for
text
,
context
in
zip
(
texts
,
contexts
):
print
(
text
)
print
(
text
)
print
(
nlu
.
predict
(
text
,
context
))
print
(
nlu
.
predict
(
text
,
context
))
...
...
This diff is collapsed.
Click to expand it.
convlab/nlu/jointBERT/unified_datasets/nlu.py
+
4
−
1
View file @
58f9a0d4
...
@@ -7,6 +7,7 @@ import transformers
...
@@ -7,6 +7,7 @@ import transformers
from
convlab.nlu.nlu
import
NLU
from
convlab.nlu.nlu
import
NLU
from
convlab.nlu.jointBERT.dataloader
import
Dataloader
from
convlab.nlu.jointBERT.dataloader
import
Dataloader
from
convlab.nlu.jointBERT.jointBERT
import
JointBERT
from
convlab.nlu.jointBERT.jointBERT
import
JointBERT
from
convlab.nlu.jointBERT.unified_datasets.preprocess
import
preprocess
from
convlab.nlu.jointBERT.unified_datasets.postprocess
import
recover_intent
from
convlab.nlu.jointBERT.unified_datasets.postprocess
import
recover_intent
from
convlab.util.custom_util
import
model_downloader
from
convlab.util.custom_util
import
model_downloader
...
@@ -25,7 +26,9 @@ class BERTNLU(NLU):
...
@@ -25,7 +26,9 @@ class BERTNLU(NLU):
data_dir
=
os
.
path
.
join
(
root_dir
,
config
[
'
data_dir
'
])
data_dir
=
os
.
path
.
join
(
root_dir
,
config
[
'
data_dir
'
])
output_dir
=
os
.
path
.
join
(
root_dir
,
config
[
'
output_dir
'
])
output_dir
=
os
.
path
.
join
(
root_dir
,
config
[
'
output_dir
'
])
assert
os
.
path
.
exists
(
os
.
path
.
join
(
data_dir
,
'
intent_vocab.json
'
)),
print
(
'
Please run preprocess first
'
)
if
not
os
.
path
.
exists
(
os
.
path
.
join
(
data_dir
,
'
intent_vocab.json
'
)):
print
(
'
Run preprocess first
'
)
preprocess
(
config
[
'
dataset_name
'
],
data_dir
.
split
(
'
/
'
)[
-
2
],
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)),
'
data
'
),
int
(
data_dir
.
split
(
'
/
'
)[
-
1
].
split
(
'
_
'
)[
-
1
]))
intent_vocab
=
json
.
load
(
open
(
os
.
path
.
join
(
data_dir
,
'
intent_vocab.json
'
)))
intent_vocab
=
json
.
load
(
open
(
os
.
path
.
join
(
data_dir
,
'
intent_vocab.json
'
)))
tag_vocab
=
json
.
load
(
open
(
os
.
path
.
join
(
data_dir
,
'
tag_vocab.json
'
)))
tag_vocab
=
json
.
load
(
open
(
os
.
path
.
join
(
data_dir
,
'
tag_vocab.json
'
)))
...
...
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