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
b770f3f0
Commit
b770f3f0
authored
Apr 21, 2022
by
zqwerty
Browse files
Options
Downloads
Patches
Plain Diff
add t5dst interface, fix bug in t5nlu,t5nlg interface that ignore context_window_size
parent
5f2f6a44
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
convlab2/base_models/t5/dst/dst.py
+69
-0
69 additions, 0 deletions
convlab2/base_models/t5/dst/dst.py
convlab2/base_models/t5/nlg/nlg.py
+10
-3
10 additions, 3 deletions
convlab2/base_models/t5/nlg/nlg.py
convlab2/base_models/t5/nlu/nlu.py
+5
-2
5 additions, 2 deletions
convlab2/base_models/t5/nlu/nlu.py
with
84 additions
and
5 deletions
convlab2/base_models/t5/dst/dst.py
0 → 100755
+
69
−
0
View file @
b770f3f0
import
logging
import
os
import
torch
from
transformers
import
AutoTokenizer
,
AutoModelForSeq2SeqLM
,
AutoConfig
from
convlab2.dst.dst
import
DST
from
convlab2.base_models.t5.dst.serialization
import
deserialize_dialogue_state
from
convlab2.util.custom_util
import
model_downloader
class
T5DST
(
DST
):
def
__init__
(
self
,
speaker
,
context_window_size
,
model_name_or_path
,
model_file
=
None
,
device
=
'
cuda
'
):
assert
speaker
in
[
'
user
'
,
'
system
'
]
assert
context_window_size
>
0
self
.
speaker
=
speaker
self
.
opponent
=
'
system
'
if
speaker
==
'
user
'
else
'
user
'
self
.
context_window_size
=
context_window_size
model_dir
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
if
not
os
.
path
.
exists
(
model_name_or_path
):
model_downloader
(
model_dir
,
model_file
)
self
.
config
=
AutoConfig
.
from_pretrained
(
model_name_or_path
)
self
.
tokenizer
=
AutoTokenizer
.
from_pretrained
(
model_name_or_path
)
self
.
model
=
AutoModelForSeq2SeqLM
.
from_pretrained
(
model_name_or_path
,
config
=
self
.
config
)
self
.
model
.
eval
()
self
.
device
=
device
if
torch
.
cuda
.
is_available
()
else
"
cpu
"
self
.
model
.
to
(
self
.
device
)
logging
.
info
(
"
T5DST loaded
"
)
def
update
(
self
,
context
):
if
len
(
context
)
>
0
and
type
(
context
[
0
])
is
list
and
len
(
context
[
0
])
>
1
:
context
=
[
item
[
1
]
for
item
in
context
]
context
=
context
[
-
self
.
context_window_size
:]
input_seq
=
'
\n
'
.
join
([
f
"
{
self
.
opponent
if
(
i
%
2
)
==
(
len
(
context
)
%
2
)
else
self
.
speaker
}
:
{
utt
}
"
for
i
,
utt
in
enumerate
(
context
)])
# print(input_seq)
input_seq
=
self
.
tokenizer
(
input_seq
,
return_tensors
=
"
pt
"
).
to
(
self
.
device
)
# print(input_seq)
output_seq
=
self
.
model
.
generate
(
**
input_seq
,
max_length
=
256
)
# print(output_seq)
output_seq
=
self
.
tokenizer
.
decode
(
output_seq
[
0
],
skip_special_tokens
=
True
)
# print(output_seq)
state
=
deserialize_dialogue_state
(
output_seq
.
strip
())
return
state
if
__name__
==
'
__main__
'
:
contexts
=
[
[
"
I would like a taxi from Saint John
'
s college to Pizza Hut Fen Ditton.
"
],
[
"
I would like a taxi from Saint John
'
s college to Pizza Hut Fen Ditton.
"
,
"
What time do you want to leave and what time do you want to arrive by?
"
,
"
I want to leave after 17:15.
"
],
[
"
I would like a taxi from Saint John
'
s college to Pizza Hut Fen Ditton.
"
,
"
What time do you want to leave and what time do you want to arrive by?
"
,
"
I want to leave after 17:15.
"
,
"
Booking completed! your taxi will be blue honda Contact number is 07218068540
"
,
"
Thank you for all the help! I appreciate it.
"
],
[
"
I would like a taxi from Saint John
'
s college to Pizza Hut Fen Ditton.
"
,
"
What time do you want to leave and what time do you want to arrive by?
"
,
"
I want to leave after 17:15.
"
,
"
Booking completed! your taxi will be blue honda Contact number is 07218068540
"
,
"
Thank you for all the help! I appreciate it.
"
,
"
You are welcome. Is there anything else I can help you with today?
"
,
"
No, I am all set. Have a nice day. Bye.
"
],
]
dst
=
T5DST
(
speaker
=
'
user
'
,
context_window_size
=
100
,
model_name_or_path
=
'
output/dst/multiwoz21/user/context_100
'
)
for
context
in
contexts
:
print
(
dst
.
update
(
context
))
print
()
This diff is collapsed.
Click to expand it.
convlab2/base_models/t5/nlg/nlg.py
+
10
−
3
View file @
b770f3f0
...
@@ -32,13 +32,14 @@ class T5NLG(NLG):
...
@@ -32,13 +32,14 @@ class T5NLG(NLG):
if
self
.
use_context
:
if
self
.
use_context
:
if
len
(
context
)
>
0
and
type
(
context
[
0
])
is
list
and
len
(
context
[
0
])
>
1
:
if
len
(
context
)
>
0
and
type
(
context
[
0
])
is
list
and
len
(
context
[
0
])
>
1
:
context
=
[
item
[
1
]
for
item
in
context
]
context
=
[
item
[
1
]
for
item
in
context
]
context
=
context
[
-
self
.
context_window_size
:]
utts
=
context
+
[
''
]
utts
=
context
+
[
''
]
else
:
else
:
utts
=
[
''
]
utts
=
[
''
]
input_seq
=
'
\n
'
.
join
([
f
"
{
self
.
opponent
if
(
i
%
2
)
==
(
len
(
utts
)
%
2
)
else
self
.
speaker
}
:
{
utt
}
"
for
i
,
utt
in
enumerate
(
utts
)])
input_seq
=
'
\n
'
.
join
([
f
"
{
self
.
opponent
if
(
i
%
2
)
==
(
len
(
utts
)
%
2
)
else
self
.
speaker
}
:
{
utt
}
"
for
i
,
utt
in
enumerate
(
utts
)])
dialogue_acts_seq
=
serialize_dialogue_acts
(
dialogue_acts
)
dialogue_acts_seq
=
serialize_dialogue_acts
(
dialogue_acts
)
input_seq
=
dialogue_acts_seq
+
'
\n
'
+
input_seq
input_seq
=
dialogue_acts_seq
+
'
\n
'
+
input_seq
print
(
input_seq
)
#
print(input_seq)
input_seq
=
self
.
tokenizer
(
input_seq
,
return_tensors
=
"
pt
"
).
to
(
self
.
device
)
input_seq
=
self
.
tokenizer
(
input_seq
,
return_tensors
=
"
pt
"
).
to
(
self
.
device
)
# print(input_seq)
# print(input_seq)
output_seq
=
self
.
model
.
generate
(
**
input_seq
,
max_length
=
256
)
output_seq
=
self
.
model
.
generate
(
**
input_seq
,
max_length
=
256
)
...
@@ -122,10 +123,16 @@ if __name__ == '__main__':
...
@@ -122,10 +123,16 @@ if __name__ == '__main__':
[
"
I would like a taxi from Saint John
'
s college to Pizza Hut Fen Ditton.
"
,
[
"
I would like a taxi from Saint John
'
s college to Pizza Hut Fen Ditton.
"
,
"
What time do you want to leave and what time do you want to arrive by?
"
,
"
What time do you want to leave and what time do you want to arrive by?
"
,
"
I want to leave after 17:15.
"
],
"
I want to leave after 17:15.
"
],
[
"
I want to leave after 17:15.
"
,
[
"
I would like a taxi from Saint John
'
s college to Pizza Hut Fen Ditton.
"
,
"
What time do you want to leave and what time do you want to arrive by?
"
,
"
I want to leave after 17:15.
"
,
"
Booking completed! your taxi will be blue honda Contact number is 07218068540
"
,
"
Booking completed! your taxi will be blue honda Contact number is 07218068540
"
,
"
Thank you for all the help! I appreciate it.
"
],
"
Thank you for all the help! I appreciate it.
"
],
[
"
Thank you for all the help! I appreciate it.
"
,
[
"
I would like a taxi from Saint John
'
s college to Pizza Hut Fen Ditton.
"
,
"
What time do you want to leave and what time do you want to arrive by?
"
,
"
I want to leave after 17:15.
"
,
"
Booking completed! your taxi will be blue honda Contact number is 07218068540
"
,
"
Thank you for all the help! I appreciate it.
"
,
"
You are welcome. Is there anything else I can help you with today?
"
"
You are welcome. Is there anything else I can help you with today?
"
"
No, I am all set. Have a nice day. Bye.
"
],
"
No, I am all set. Have a nice day. Bye.
"
],
]
]
...
...
This diff is collapsed.
Click to expand it.
convlab2/base_models/t5/nlu/nlu.py
+
5
−
2
View file @
b770f3f0
...
@@ -32,6 +32,7 @@ class T5NLU(NLU):
...
@@ -32,6 +32,7 @@ class T5NLU(NLU):
if
self
.
use_context
:
if
self
.
use_context
:
if
len
(
context
)
>
0
and
type
(
context
[
0
])
is
list
and
len
(
context
[
0
])
>
1
:
if
len
(
context
)
>
0
and
type
(
context
[
0
])
is
list
and
len
(
context
[
0
])
>
1
:
context
=
[
item
[
1
]
for
item
in
context
]
context
=
[
item
[
1
]
for
item
in
context
]
context
=
context
[
-
self
.
context_window_size
:]
utts
=
context
+
[
utterance
]
utts
=
context
+
[
utterance
]
else
:
else
:
utts
=
[
utterance
]
utts
=
[
utterance
]
...
@@ -60,13 +61,15 @@ if __name__ == '__main__':
...
@@ -60,13 +61,15 @@ if __name__ == '__main__':
[],
[],
[
"
I would like a taxi from Saint John
'
s college to Pizza Hut Fen Ditton.
"
,
[
"
I would like a taxi from Saint John
'
s college to Pizza Hut Fen Ditton.
"
,
"
What time do you want to leave and what time do you want to arrive by?
"
],
"
What time do you want to leave and what time do you want to arrive by?
"
],
[
"
What time do you want to leave and what time do you want to arrive by?
"
,
[
"
I would like a taxi from Saint John
'
s college to Pizza Hut Fen Ditton.
"
,
"
What time do you want to leave and what time do you want to arrive by?
"
,
"
I want to leave after 17:15.
"
,
"
I want to leave after 17:15.
"
,
"
Booking completed! your taxi will be blue honda Contact number is 07218068540
"
],
"
Booking completed! your taxi will be blue honda Contact number is 07218068540
"
],
[],
[],
[
"
Please find a restaurant called Nusha.
"
,
[
"
Please find a restaurant called Nusha.
"
,
"
I don
'
t seem to be finding anything called Nusha. What type of food does the restaurant serve?
"
],
"
I don
'
t seem to be finding anything called Nusha. What type of food does the restaurant serve?
"
],
[
"
I don
'
t seem to be finding anything called Nusha. What type of food does the restaurant serve?
"
,
[
"
Please find a restaurant called Nusha.
"
,
"
I don
'
t seem to be finding anything called Nusha. What type of food does the restaurant serve?
"
,
"
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.
"
]
]
]
...
...
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