ner-few-shot

This commit is contained in:
lilei 2021-09-27 09:06:04 -05:00 committed by GitHub
parent 275cd070a3
commit f6f375d7cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
30 changed files with 555485 additions and 0 deletions

View File

@ -0,0 +1,56 @@
## 快速上手
### 环境依赖
> python == 3.8
- torch == 1.7
- tensorboardX ==2.4
- transformers == 3.4.0
- deepke
### 克隆代码
```
git clone git@github.com:zjunlp/DeepKE.git
```
### 使用pip安装
首先创建python虚拟环境再进入虚拟环境
- 安装依赖: ```pip install -r requirements.txt```
### 使用数据进行训练预测
- 存放数据:在 `data` 文件夹下存放训练数据。包含conll2003mit-moviemit-restaurant和atis等数据集。
- conll2003包含以下数据
- `train.txt`:存放训练数据集
- `dev.txt`:存放验证数据集
- `test.txt`:存放测试数据集
- `indomain-train.txt`存放indomain数据集
- mit-movie, mit-restaurant和atis包含以下数据
- `k-shot-train.txt`k=[10, 20, 50, 100, 200, 500],存放训练数据集
- `test.txt`:存放测试数据集
- 开始训练模型加载和保存位置以及配置可以在shell脚本中修改
- 训练conll2003` python run.py ` (训练所用到参数都在conf文件夹中修改即可)
- 进行few-shot训练` python run.py +train=few_shot ` (若要加载模型修改few_shot.yaml中的load_path)
- 每次训练的日志保存在 `logs` 文件夹内,模型结果保存目录可以自定义。
- 进行预测: ` python predict.py `
## 模型内容
LightNER

View File

@ -0,0 +1,4 @@
cwd: ???
defaults:
- train/conll

View File

@ -0,0 +1,29 @@
cwd: ???
defaults:
seed: 1
bart_name: "facebook/bart-large"
dataset_name: conll2003
device: cuda
num_epochs: 30
batch_size: 16
learning_rate: 2e-5
warmup_ratio: 0.01
eval_begin_epoch: 16
src_seq_ratio: 0.6
tgt_max_len: 10
num_beams: 1
length_penalty: 1
use_prompt: True
prompt_len: 10
prompt_dim: 800
freeze_plm: True
learn_weights: True
notes: ''
save_path: null # 模型保存路径
load_path: load_path # 模型加载路径,不能为空
write_path: "data/conll2003/predict.txt"

View File

@ -0,0 +1,25 @@
seed: 1
bart_name: "/data/lilei/project/BARTNER-AMAX/facebook/bart-large"
dataset_name: conll2003
device: cuda
num_epochs: 30
batch_size: 16
learning_rate: 2e-5
warmup_ratio: 0.01
eval_begin_epoch: 16
src_seq_ratio: 0.6
tgt_max_len: 10
num_beams: 1
length_penalty: 1
use_prompt: True
prompt_len: 10
prompt_dim: 800
freeze_plm: True
learn_weights: True
save_path: save path # 模型保存路径
load_path: null
notes: ''

View File

@ -0,0 +1,25 @@
seed: 1
bart_name: "/data/lilei/project/BARTNER-AMAX/facebook/bart-large"
dataset_name: mit-movie
device: cuda
num_epochs: 30
batch_size: 16
learning_rate: 1e-4
warmup_ratio: 0.01
eval_begin_epoch: 16
src_seq_ratio: 0.8
tgt_max_len: 10
num_beams: 1
length_penalty: 1
use_prompt: True
prompt_len: 10
prompt_dim: 800
freeze_plm: True
learn_weights: True
save_path: null # 模型保存路径
load_path: null # 模型加载路径,
notes: ''

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,558 @@
-DOCSTART- O
please O
find O
a O
movie O
starring O
al B-ACTOR
pacino I-ACTOR
as O
a O
blind B-CHARACTER
veteran I-CHARACTER
who O
is O
in O
justin B-TITLE
time I-TITLE
what O
was O
the O
title O
of O
the O
movie O
of O
julia B-ACTOR
roberts I-ACTOR
academy B-REVIEW
award I-REVIEW
winning I-REVIEW
perfrmance I-REVIEW
who O
created O
the O
soundtrak B-SONG
for O
star B-TRAILER
wars I-TRAILER
who O
was O
the O
voice O
of O
ariel B-CHARACTER
in O
the O
little B-TITLE
mermaid I-TITLE
find O
clips B-TRAILER
of O
men B-TITLE
in I-TITLE
black I-TITLE
ii I-TITLE
what O
is O
the O
plot O
of O
red B-TITLE
tails I-TITLE
do O
you O
know O
of O
any O
movie O
that O
had O
come B-SONG
what I-SONG
may I-SONG
in O
its O
soundtrack O
i O
want O
to O
know O
what O
movies O
have O
the O
song O
come B-SONG
what I-SONG
may I-SONG
show O
me O
the O
half B-SONG
baked I-SONG
soundtrack I-SONG
find O
me O
a O
list O
of O
bette B-ACTOR
midler I-ACTOR
movies O
from O
the O
1980s B-YEAR
get O
a O
yul B-ACTOR
brenner I-ACTOR
western B-GENRE
play O
trailer B-TRAILER
on B-TITLE
stranger I-TITLE
tides I-TITLE
who O
played O
james B-CHARACTER
bond I-CHARACTER
in O
goldfinger B-TITLE
what O
is O
an O
ok B-RATINGS_AVERAGE
pg B-RATING
13 I-RATING
adventure B-GENRE
directed O
by O
mac B-DIRECTOR
carter I-DIRECTOR
who O
is O
the O
main B-CHARACTER
character O
of O
a B-TITLE
bronx I-TITLE
tale I-TITLE
find O
a O
preview B-TRAILER
for O
a O
elizabeth B-ACTOR
perkins I-ACTOR
period B-PLOT
piece I-PLOT
movie O
looking O
for O
the O
movie O
with O
broderick B-ACTOR
crawford I-ACTOR
as O
the O
governor B-CHARACTER
of I-CHARACTER
louisiana I-CHARACTER
find O
me O
a O
movie O
with O
the O
song O
my B-SONG
heart I-SONG
will I-SONG
go I-SONG
on I-SONG
list O
a O
crime B-GENRE
film O
which O
director O
was O
david B-DIRECTOR
lean I-DIRECTOR
when O
did O
little B-TITLE
man I-TITLE
come O
out O
on O
dvd O
what O
are O
the O
best B-REVIEW
horror B-GENRE
movies O
from O
2004 B-YEAR
how O
many O
james B-CHARACTER
bond I-CHARACTER
movies O
are O
there O
do O
you O
think O
project B-TITLE
x I-TITLE
is O
better B-REVIEW
than O
hangover B-TITLE
who O
directed O
cello B-TITLE
eng I-TITLE
subs I-TITLE
run O
twilight B-TITLE
zone I-TITLE
name O
the O
thriller B-GENRE
starring O
jack B-ACTOR
haley I-ACTOR
from O
1960 B-YEAR
that O
is O
rated O
pg B-RATING
13 I-RATING
with O
a O
ratings O
average O
of O
four B-RATINGS_AVERAGE
find O
a O
five B-RATINGS_AVERAGE
star I-RATINGS_AVERAGE
karate B-GENRE
movie O
name O
the O
the O
sequel O
of O
the O
movie O
pitch B-TITLE
black I-TITLE
starring O
vin O
diesel O
has O
ingmar B-DIRECTOR
bergman I-DIRECTOR
ever O
directed O
any O
r B-RATING
rated O
thriller B-GENRE
films O
find O
me O
fantasy B-GENRE
films O
starring O
warwick B-ACTOR
davis I-ACTOR
find O
a O
kids B-GENRE
movie I-GENRE
with O
benji B-CHARACTER
the I-CHARACTER
dog I-CHARACTER
was O
a B-TITLE
beautiful I-TITLE
mind I-TITLE
an O
original B-SONG
score I-SONG
i O
wish O
to O
see O
reviews B-REVIEW
from O
common O
people O
who O
watched O
the O
movie O
already O
how O
many O
james B-CHARACTER
bond I-CHARACTER
movies O
did O
sean B-ACTOR
connery I-ACTOR
star O
in O
in O
the O
past B-YEAR
nine I-YEAR
years I-YEAR
there O
was O
a O
sci B-GENRE
fi I-GENRE
movie O
that O
was O
directed O
by O
paddy B-DIRECTOR
breathnach I-DIRECTOR
and O
received O
nine B-RATINGS_AVERAGE
stars I-RATINGS_AVERAGE
also O
included O
parasites B-PLOT
what O
was O
it O
suggest O
a O
movie O
for O
family B-REVIEW
night I-REVIEW
run O
a O
trailer B-TRAILER
for O
a O
stanley B-DIRECTOR
kubrik I-DIRECTOR
epic B-GENRE
what O
are O
people B-REVIEW
saying I-REVIEW
about O
willy B-TITLE
wonka I-TITLE
the I-TITLE
chocolate I-TITLE
factory I-TITLE
find O
a O
trailer B-TRAILER
for O
last B-TITLE
of I-TITLE
the I-TITLE
mohicans I-TITLE
show O
me O
a O
movie O
with O
the O
song O
some B-SONG
day I-SONG
my I-SONG
prince I-SONG
will I-SONG
come I-SONG
could O
you O
tell O
me O
the O
titles O
of O
the O
pg B-RATING
13 I-RATING
family B-GENRE
films O
from O
the O
past B-YEAR
three I-YEAR
decades I-YEAR
by O
director O
david B-DIRECTOR
presley I-DIRECTOR
that O
have O
a O
ratings O
average O
of O
highly B-RATINGS_AVERAGE
recommended I-RATINGS_AVERAGE
what O
would O
be O
the O
best O
short B-GENRE
movie O
to O
watch O
starring O
rene B-ACTOR
russo I-ACTOR
that O
was O
made O
in O
the O
last B-YEAR
six I-YEAR
years I-YEAR
did O
barbra B-ACTOR
streisand I-ACTOR
do O
any O
comedies B-GENRE
what O
g B-RATING
rated O
drama B-GENRE
with O
humphrey B-ACTOR
bogart I-ACTOR
did O
ok B-RATINGS_AVERAGE
find O
me O
the O
movie O
with O
the O
song O
blue B-SONG
hawaii I-SONG
what O
are O
some O
good B-REVIEW
g B-RATING
rated O
movies O
for O
kids B-REVIEW
im O
looking O
for O
im B-TITLE
not I-TITLE
there I-TITLE
what O
horror B-GENRE
movie O
features O
a O
character B-PLOT
coming I-PLOT
out I-PLOT
of I-PLOT
a I-PLOT
tv I-PLOT
screen I-PLOT
get O
me O
some O
razzie B-REVIEW
award I-REVIEW
winners I-REVIEW
from O
2010 B-YEAR
find O
a O
preview B-TRAILER
for O
a O
elizabeth B-ACTOR
taylor I-ACTOR
period B-GENRE
piece I-GENRE
movie O

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,456 @@
-DOCSTART- O
what O
restaurant O
serves O
tapas B-Dish
on O
forbes B-Location
road I-Location
that O
has O
celebrities B-Amenity
visiting I-Amenity
often I-Amenity
can O
you O
find O
a O
restaurant O
near B-Location
downtown I-Location
that O
serves O
french B-Cuisine
cuisine O
navigate O
me O
to O
a O
good B-Rating
thai B-Cuisine
restaurant O
is O
there O
a O
cafe B-Restaurant_Name
rio I-Restaurant_Name
within B-Location
ten I-Location
miles I-Location
that O
is O
not B-Price
expensive I-Price
do O
you O
know O
if O
the O
chinese B-Cuisine
restaurant O
on O
king B-Location
street I-Location
have O
outdoor B-Amenity
parking I-Amenity
is O
kostas B-Restaurant_Name
pizza I-Restaurant_Name
and I-Restaurant_Name
seafood I-Restaurant_Name
cheap B-Price
can O
you O
find O
a O
well B-Rating
rated I-Rating
japanese B-Cuisine
restaurant O
with O
parking B-Amenity
where O
can O
i O
get O
a O
martini B-Dish
after B-Hours
1 I-Hours
am I-Hours
in B-Location
faneuil I-Location
hall I-Location
square I-Location
i O
want O
to O
take O
my O
date O
to O
a O
restaurant O
that O
has O
good B-Rating
mushrooms B-Cuisine
find O
me O
the O
phone O
number O
of O
the O
closest B-Location
restaurant O
what O
mcdonalds B-Restaurant_Name
are O
there O
near B-Location
hitown I-Location
city I-Location
that O
are O
still B-Hours
open I-Hours
is O
ngon B-Restaurant_Name
bistro I-Restaurant_Name
open B-Hours
right I-Hours
now I-Hours
can O
i O
get O
to O
a O
place O
that O
is O
within B-Location
five I-Location
minutes I-Location
and O
open B-Hours
before I-Hours
noon I-Hours
does O
the O
german B-Cuisine
restaurant O
within B-Location
5 I-Location
miles I-Location
of I-Location
here I-Location
offer O
carry B-Amenity
out I-Amenity
i O
would O
like O
a O
listing O
of O
olive B-Restaurant_Name
gardens I-Restaurant_Name
in B-Location
the I-Location
area I-Location
where O
can O
i O
get O
some O
good B-Rating
home B-Dish
made I-Dish
soup I-Dish
is O
there O
place O
five B-Location
minutes I-Location
from I-Location
here I-Location
with O
a O
good B-Price
price O
with O
vegetable B-Dish
dishes O
find O
a O
mcdonalds B-Restaurant_Name
near B-Location
here I-Location
where O
can O
i O
get O
carry B-Amenity
out I-Amenity
chinese B-Cuisine
food O
in O
glen B-Location
cove I-Location
new I-Location
york I-Location
does O
the O
nearest B-Location
steakhouse B-Cuisine
take O
diners B-Amenity
club I-Amenity
locate O
any O
fast B-Cuisine
food I-Cuisine
restaurant O
other B-Amenity
than I-Amenity
kfc B-Restaurant_Name
that O
is O
within B-Location
3 I-Location
miles I-Location
im O
feeling O
mexican B-Cuisine
food O
i O
need O
a O
cheap B-Price
place O
with O
a O
strong B-Rating
rating I-Rating
is O
there O
an O
italian B-Cuisine
restaurant O
along B-Location
my I-Location
route I-Location
that O
has O
a O
lot O
of O
parking B-Amenity
space I-Amenity
whats O
the O
best B-Rating
place O
to O
eat O
in O
a O
downtown B-Location
hotel I-Location
can O
you O
find O
me O
a O
restaurant O
that O
serves O
vegetarian B-Dish
meatloaf I-Dish
is O
the O
jamaica B-Restaurant_Name
plain I-Restaurant_Name
house I-Restaurant_Name
pizza I-Restaurant_Name
restaurant O
cheap O
i O
need O
to O
make O
reservations B-Amenity
for O
three O
at O
alfredos B-Restaurant_Name
for O
tomorrow B-Hours
night I-Hours
at I-Hours
6 I-Hours
pm I-Hours
im O
wanting O
to O
drink O
a O
lot O
of O
wine B-Dish
who O
gives O
you O
a O
lot B-Price
of I-Price
wine I-Price
for I-Price
the I-Price
money I-Price
thats O
within B-Location
5 I-Location
miles I-Location
i O
want O
to O
find O
the O
closest B-Location
olive B-Restaurant_Name
garden I-Restaurant_Name
where O
are O
the O
very O
highly B-Rating
rated I-Rating
and O
reasonably B-Price
priced O
restaurants O
id O
like O
to O
try O
a O
four B-Rating
star I-Rating
restaurant O
that O
has O
a O
lunch B-Hours
menu O
find O
me O
someplace O
with O
awesome B-Rating
barbecue B-Dish
dishes O
in O
holbrook B-Location
where O
can O
i O
get O
the O
best B-Rating
cake B-Dish
im O
craving O
some O
cheap B-Price
sausages B-Dish
who O
has O
that O
and O
opens B-Hours
before I-Hours
noon I-Hours
im O
looking O
for O
a O
not B-Price
too I-Price
espensive I-Price
restaurant O
that O
offers O
halal B-Cuisine
food O
what O
is O
the O
rating B-Rating
on O
subway B-Restaurant_Name
is O
there O
a O
starbucks B-Restaurant_Name
nearby B-Location
is O
there O
a O
steak B-Cuisine
house I-Cuisine
still B-Hours
open I-Hours
in B-Location
this I-Location
city I-Location
wheres O
the O
closest B-Location
restaurant O
with O
free B-Amenity
wifi I-Amenity

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,909 @@
-DOCSTART- O
how O
much O
does O
it O
cost O
to O
eat O
at O
mickeys B-Restaurant_Name
diner I-Restaurant_Name
per O
person O
is O
there O
a O
good B-Rating
cafe B-Cuisine
near O
dolores B-Location
park I-Location
are O
there O
any O
cafes B-Cuisine
open B-Hours
past I-Hours
11 I-Hours
pm I-Hours
which O
have O
internet B-Amenity
access I-Amenity
where O
is O
a O
restaurant O
that O
has O
a O
smoking B-Amenity
area I-Amenity
what O
is O
the O
top B-Rating
rated I-Rating
restaurant O
in O
helena B-Location
montana I-Location
what O
restaurant O
serves O
the O
largest B-Dish
pizza I-Dish
in B-Location
town I-Location
a O
sub B-Dish
place O
near B-Location
independence I-Location
boulevard I-Location
i O
want O
a O
cold O
draft B-Dish
beer I-Dish
in O
the O
shade B-Amenity
find O
me O
a O
japanese B-Cuisine
restaurant O
serving O
japanese B-Cuisine
food O
who O
has O
some O
good B-Rating
chicken B-Dish
soup I-Dish
im O
looking O
for O
a O
restaurant O
with O
a O
romantic B-Amenity
atmosphere I-Amenity
but O
isnt B-Price
too I-Price
expensive I-Price
name O
a O
price O
place O
with O
hungarian B-Cuisine
cuisine O
lets O
find O
a O
coffee B-Cuisine
place O
within B-Location
5 I-Location
miles I-Location
of I-Location
here I-Location
where O
can O
i O
get O
not B-Price
so I-Price
cheap I-Price
chocolate B-Dish
cake I-Dish
and O
be O
able O
to O
byob B-Amenity
is O
there O
a O
burger B-Restaurant_Name
king I-Restaurant_Name
near B-Location
my I-Location
current I-Location
location I-Location
find O
a O
big B-Dish
mac I-Dish
from O
mcdonalds B-Restaurant_Name
around B-Location
me I-Location
take O
me O
somewhere O
nice B-Amenity
to O
eat O
can O
you O
get O
me O
directions O
to O
the O
closest B-Location
seafood B-Cuisine
restaurant O
what O
fine B-Amenity
dining I-Amenity
restaurants O
are O
open O
for O
dinner B-Hours
and O
feature O
lunch B-Amenity
specials I-Amenity
is O
there O
any O
restaurant O
that O
has O
good B-Rating
reviews I-Rating
but O
is O
also O
vegan B-Amenity
i O
could O
go O
for O
some O
mexican B-Cuisine
food O
know O
where O
i O
can O
get O
some O
can O
you O
show O
me O
where O
to O
go O
for O
spit B-Dish
buffalo I-Dish
wings I-Dish
and O
handcrafted B-Dish
beer I-Dish
near B-Location
my O
home B-Location
im O
hungry O
wheres O
the O
nearest B-Location
restaurant O
is O
there O
a O
puleos B-Restaurant_Name
dairy I-Restaurant_Name
in B-Location
north I-Location
square I-Location
that O
is O
a O
place O
the O
local B-Rating
people I-Rating
like I-Rating
search O
for O
a O
moderately B-Price
priced O
italian B-Cuisine
restaurant O
near B-Location
my I-Location
current I-Location
location I-Location
nearest B-Location
red B-Restaurant_Name
lobster I-Restaurant_Name
in B-Location
town I-Location
where O
can O
i O
find O
cheap B-Price
chinese B-Cuisine
food O
are O
there O
any O
diners O
open B-Hours
before I-Hours
5 I-Hours
am I-Hours
that O
allow B-Amenity
smoking I-Amenity
what O
is O
the O
most O
inexpensive B-Price
restaurant O
hi O
i O
am O
looking O
for O
a O
great B-Rating
mexican B-Cuisine
resturant O
with O
really O
fast B-Amenity
service I-Amenity
any O
suggestions O
looking O
for O
cheap B-Price
eats O
around B-Location
here I-Location
is O
there O
a O
kid B-Amenity
friendly I-Amenity
hot B-Dish
wings I-Dish
place O
in O
dixie B-Location
inn I-Location
get O
me O
to O
the O
nearest B-Location
car O
repair O
shop O
in O
town O
take O
me O
to O
the O
cheapest B-Price
pizza B-Cuisine
place O
that O
has O
anchovies B-Dish
can O
i O
get O
the O
phone O
number O
for O
the O
nearest B-Location
five B-Rating
star I-Rating
restaurant O
can O
i O
get O
the O
phone O
number O
of O
a O
restaurant O
for O
carry B-Amenity
out I-Amenity
order O
of O
spicy B-Dish
buffalo I-Dish
wings I-Dish
i O
would O
like O
a O
dinner B-Cuisine
in B-Location
my I-Location
area I-Location
please I-Location
is O
there O
a O
restaurant O
near B-Location
here I-Location
that O
offers O
carry B-Amenity
out I-Amenity
service I-Amenity
what O
is O
the O
name O
of O
the O
upscale B-Amenity
restaurant O
inside O
the O
marriott B-Location
hotel I-Location
of I-Location
the I-Location
shoals I-Location
find O
out O
where O
the O
closest B-Location
panda B-Restaurant_Name
chinese I-Restaurant_Name
restaurant O
is O
where O
can O
i O
find O
garlic B-Dish
eggplant I-Dish
i O
want O
to O
find O
a O
black B-Amenity
tie I-Amenity
restaurant O
that O
would O
be O
good B-Rating
to O
take O
someone B-Amenity
on I-Amenity
a I-Amenity
date I-Amenity
id O
like O
to O
find O
a O
decent B-Rating
italian B-Cuisine
restaurant O
near B-Location
by I-Location
what O
time O
does O
applebees B-Restaurant_Name
in O
san B-Location
leandro I-Location
open B-Hours
do O
you O
know O
the O
health B-Rating
ratings I-Rating
of O
restaurants O
whats O
an O
average B-Price
priced O
restaurant O
thats O
open B-Hours
at I-Hours
11 I-Hours
am I-Hours
i O
want O
to O
find O
a O
goos B-Restaurant_Name
delivery B-Amenity
pizza B-Cuisine
place O
where O
can O
i O
find O
a O
family B-Amenity
style I-Amenity
place O
price B-Price
doesnt I-Price
matter I-Price
is O
there O
a O
colombian B-Cuisine
buffet B-Amenity
close B-Location
by I-Location
where O
is O
the O
nearest O
olive B-Restaurant_Name
garden I-Restaurant_Name
restaurant O
to O
zip B-Location
code I-Location
04032 I-Location
i O
would O
like O
the O
closest B-Location
japanese B-Cuisine
restaurant O
with O
free B-Amenity
parking I-Amenity
find O
me O
a O
place O
where O
i O
can O
just O
get O
a O
light B-Dish
lunch I-Dish
that O
wouldnt O
be O
bad O
for B-Amenity
someone I-Amenity
on I-Amenity
a I-Amenity
diet I-Amenity
is O
taco B-Restaurant_Name
bell I-Restaurant_Name
still B-Hours
open I-Hours
find O
me O
a O
cheap B-Price
sushi B-Cuisine
restaurant O
where O
is O
a O
cheap B-Price
belgian B-Cuisine
restaurant O
on O
the O
north B-Location
end I-Location
does O
the O
new O
mexican B-Cuisine
restaurant O
have O
good B-Rating
reviews I-Rating
what O
are O
the O
hours O
of O
the O
nearest B-Location
shoneys B-Restaurant_Name
breakfast I-Restaurant_Name
bar I-Restaurant_Name
today O
is O
there O
a O
restaurant O
within B-Location
25 I-Location
miles I-Location
that O
serves O
pizza B-Dish
with I-Dish
gluten B-Amenity
free I-Amenity
crust B-Dish
im O
looking O
for O
a O
cheap B-Price
restaurant O
are O
than O
any O
sushi B-Cuisine
restaurants O
on O
the O
north B-Location
side I-Location
of I-Location
town I-Location
and O
i O
need O
to O
know O
their O
phone O
number O
and O
directions O
make O
me O
a O
reservation O
for O
4 O
people O
tonight B-Hours
at O
the O
best B-Rating
sushi B-Cuisine
restaurant O
in B-Location
this I-Location
city I-Location
please O
make O
me O
a O
reservation O
at O
the O
best B-Rating
rated I-Rating
restaurant O
with O
modern B-Cuisine
american I-Cuisine
cuisine O
thank O
you O
show O
me O
restaurants O
that B-Hours
are I-Hours
open I-Hours
does O
michaels B-Restaurant_Name
have O
a O
smoking B-Amenity
area I-Amenity
where O
can O
i O
find O
the O
best B-Rating
desserts B-Cuisine
made O
with O
real B-Amenity
cane I-Amenity
sugar I-Amenity
do O
they O
have O
good B-Price
waterfront B-Amenity
dining I-Amenity
what O
is O
the O
best B-Rating
rated I-Rating
restaurant O
near B-Location
the I-Location
next I-Location
exit I-Location
for O
bismark B-Location
north I-Location
dakota I-Location
make O
reservations O
at O
olive B-Restaurant_Name
garden I-Restaurant_Name
on O
main B-Location
street I-Location
wheres O
the O
closest B-Location
deli B-Cuisine
i O
am O
looking O
for O
a O
restaurant O
that O
features O
wild B-Dish
game I-Dish
in B-Location
the I-Location
area I-Location
where O
is O
the O
closet B-Location
fast B-Cuisine
food I-Cuisine
restaurant O
can O
you O
look O
for O
an O
italian B-Cuisine
restaurant O
in O
this B-Location
area I-Location
is O
there O
a O
spuds B-Restaurant_Name
with O
lots B-Amenity
of I-Amenity
beer I-Amenity
selections I-Amenity
does O
nobles B-Restaurant_Name
on O
main B-Location
have O
valet B-Amenity
parking I-Amenity
where O
can O
i O
get O
sushi B-Dish
that O
isnt B-Price
real I-Price
pricey O
is O
there O
an O
upscale B-Restaurant_Name
french B-Cuisine
restaurant B-Restaurant_Name
in O
this O
part O
of O
town B-Location
that O
doesnt O
require O
a O
reservation O
do O
you O
show O
any O
mcdonalds B-Restaurant_Name
nearby B-Location
are O
there O
any O
italian B-Cuisine
restaurants O
open B-Hours
before I-Hours
7 I-Hours
am I-Hours
i O
want O
the O
phone O
numbers O
to O
the O
best B-Rating
5 I-Rating
star I-Rating
restaurants O
in O
nyc B-Location
where O
can O
i O
get O
a O
cheap B-Price
meal O
before B-Hours
8 I-Hours
am I-Hours
can O
you O
make O
reservations O
for O
a O
party O
of O
eight O
at O
the O
north B-Restaurant_Name
brook I-Restaurant_Name
diner I-Restaurant_Name

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,99 @@
import os
os.environ["CUDA_DEVICE_ORDER"]="PCI_BUS_ID"
os.environ["CUDA_VISIBLE_DEVICES"]='0'
import logging
import sys
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../")))
import hydra
from hydra import utils
from torch.utils.data import DataLoader
from deepke.name_entity_re.few_shot.models.model import PromptBartModel, PromptGeneratorModel
from deepke.name_entity_re.few_shot.module.datasets import ConllNERProcessor, ConllNERDataset
from deepke.name_entity_re.few_shot.module.train import Trainer
from deepke.name_entity_re.few_shot.utils.utils import set_seed
from deepke.name_entity_re.few_shot.module.mapping_type import mit_movie_mapping, mit_restaurant_mapping, atis_mapping
import warnings
warnings.filterwarnings("ignore", category=UserWarning)
from tensorboardX import SummaryWriter
writer = SummaryWriter(log_dir='logs')
logging.basicConfig(format = '%(asctime)s - %(levelname)s - %(name)s - %(message)s',
datefmt = '%m/%d/%Y %H:%M:%S',
level = logging.INFO)
logger = logging.getLogger(__name__)
DATASET_CLASS = {
'conll2003': ConllNERDataset,
'mit-movie': ConllNERDataset,
'mit-restaurant': ConllNERDataset,
'atis': ConllNERDataset
}
DATA_PROCESS = {
'conll2003': ConllNERProcessor,
'mit-movie': ConllNERProcessor,
'mit-restaurant': ConllNERProcessor,
'atis': ConllNERProcessor
}
DATA_PATH = {
'conll2003': {'train': 'data/conll2003/train.txt',
'dev': 'data/conll2003/dev.txt',
'test': 'data/conll2003/test.txt'},
'mit-movie': {'train': 'data/mit-movie/20-shot-train.txt',
'dev': 'data/mit-movie/test.txt'},
'mit-restaurant': {'train': 'data/mit-restaurant/10-shot-train.txt',
'dev': 'data/mit-restaurant/test.txt'},
'atis': {'train': 'data/atis/20-shot-train.txt',
'dev': 'data/atis/test.txt'}
}
MAPPING = {
'conll2003': {'loc': '<<location>>',
'per': '<<person>>',
'org': '<<organization>>',
'misc': '<<others>>'},
'mit-movie': mit_movie_mapping,
'mit-restaurant': mit_restaurant_mapping,
'atis': atis_mapping
}
@hydra.main(config_path="conf/config.yaml")
def main(cfg):
cwd = utils.get_original_cwd()
cfg.cwd = cwd
print(cfg)
data_path = DATA_PATH[cfg.dataset_name]
for mode, path in data_path.items():
data_path[mode] = os.path.join(cfg.cwd, path)
dataset_class, data_process = DATASET_CLASS[cfg.dataset_name], DATA_PROCESS[cfg.dataset_name]
mapping = MAPPING[cfg.dataset_name]
set_seed(cfg.seed) # set seed, default is 1
if cfg.save_path is not None: # make save_path dir
cfg.save_path = os.path.join(cfg.save_path, cfg.dataset_name+"_"+str(cfg.batch_size)+"_"+str(cfg.learning_rate)+cfg.notes)
if not os.path.exists(cfg.save_path):
os.makedirs(cfg.save_path, exist_ok=True)
process = data_process(data_path=data_path, mapping=mapping, bart_name=cfg.bart_name, learn_weights=cfg.learn_weights)
test_dataset = dataset_class(data_processor=process, mode='test')
test_dataloader = DataLoader(test_dataset, collate_fn=test_dataset.collate_fn, batch_size=cfg.batch_size, num_workers=4)
label_ids = list(process.mapping2id.values())
prompt_model = PromptBartModel(tokenizer=process.tokenizer, label_ids=label_ids, args=cfg)
model = PromptGeneratorModel(prompt_model=prompt_model, bos_token_id=0,
eos_token_id=1,
max_length=cfg.tgt_max_len, max_len_a=cfg.src_seq_ratio,num_beams=cfg.num_beams, do_sample=False,
repetition_penalty=1, length_penalty=cfg.length_penalty, pad_token_id=1,
restricter=None)
trainer = Trainer(train_data=None, dev_data=None, test_data=test_dataloader, model=model, process=process, args=cfg, logger=logger, loss=None, metrics=None, writer=writer)
trainer.predict()
if __name__ == "__main__":
main()

View File

@ -0,0 +1,3 @@
transformers==3.4.0
pytorch==1.7.0
tensorboardX==2.4

109
example/ner/few-shot/run.py Normal file
View File

@ -0,0 +1,109 @@
import os
import hydra
os.environ["CUDA_DEVICE_ORDER"]="PCI_BUS_ID"
os.environ["CUDA_VISIBLE_DEVICES"]='1'
import logging
import sys
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../")))
from hydra import utils
from torch.utils.data import DataLoader
from deepke.name_entity_re.few_shot.models.model import PromptBartModel, PromptGeneratorModel
from deepke.name_entity_re.few_shot.module.datasets import ConllNERProcessor, ConllNERDataset
from deepke.name_entity_re.few_shot.module.train import Trainer
from deepke.name_entity_re.few_shot.module.metrics import Seq2SeqSpanMetric
from deepke.name_entity_re.few_shot.utils.utils import get_loss, set_seed
from deepke.name_entity_re.few_shot.module.mapping_type import mit_movie_mapping, mit_restaurant_mapping, atis_mapping
import warnings
warnings.filterwarnings("ignore", category=UserWarning)
from tensorboardX import SummaryWriter
writer = SummaryWriter(log_dir='logs')
logging.basicConfig(format = '%(asctime)s - %(levelname)s - %(name)s - %(message)s',
datefmt = '%m/%d/%Y %H:%M:%S',
level = logging.INFO)
logger = logging.getLogger(__name__)
DATASET_CLASS = {
'conll2003': ConllNERDataset,
'mit-movie': ConllNERDataset,
'mit-restaurant': ConllNERDataset,
'atis': ConllNERDataset
}
DATA_PROCESS = {
'conll2003': ConllNERProcessor,
'mit-movie': ConllNERProcessor,
'mit-restaurant': ConllNERProcessor,
'atis': ConllNERProcessor
}
DATA_PATH = {
'conll2003': {'train': 'data/conll2003/train.txt',
'dev': 'data/conll2003/dev.txt',
'test': 'data/conll2003/test.txt'},
'mit-movie': {'train': 'data/mit-movie/20-shot-train.txt',
'dev': 'data/mit-movie/test.txt'},
'mit-restaurant': {'train': 'data/mit-restaurant/10-shot-train.txt',
'dev': 'data/mit-restaurant/test.txt'},
'atis': {'train': 'data/atis/20-shot-train.txt',
'dev': 'data/atis/test.txt'}
}
MAPPING = {
'conll2003': {'loc': '<<location>>',
'per': '<<person>>',
'org': '<<organization>>',
'misc': '<<others>>'},
'mit-movie': mit_movie_mapping,
'mit-restaurant': mit_restaurant_mapping,
'atis': atis_mapping
}
@hydra.main(config_path="conf/config.yaml")
def main(cfg):
cwd = utils.get_original_cwd()
cfg.cwd = cwd
print(cfg)
data_path = DATA_PATH[cfg.dataset_name]
for mode, path in data_path.items():
data_path[mode] = os.path.join(cfg.cwd, path)
dataset_class, data_process = DATASET_CLASS[cfg.dataset_name], DATA_PROCESS[cfg.dataset_name]
mapping = MAPPING[cfg.dataset_name]
set_seed(cfg.seed) # set seed, default is 1
if cfg.save_path is not None: # make save_path dir
cfg.save_path = os.path.join(cfg.save_path, cfg.dataset_name+"_"+str(cfg.batch_size)+"_"+str(cfg.learning_rate)+cfg.notes)
if not os.path.exists(cfg.save_path):
os.makedirs(cfg.save_path, exist_ok=True)
process = data_process(data_path=data_path, mapping=mapping, bart_name=cfg.bart_name, learn_weights=cfg.learn_weights)
train_dataset = dataset_class(data_processor=process, mode='train')
train_dataloader = DataLoader(train_dataset, collate_fn=train_dataset.collate_fn, batch_size=cfg.batch_size, num_workers=4)
dev_dataset = dataset_class(data_processor=process, mode='dev')
dev_dataloader = DataLoader(dev_dataset, collate_fn=dev_dataset.collate_fn, batch_size=cfg.batch_size, num_workers=4)
label_ids = list(process.mapping2id.values())
prompt_model = PromptBartModel(tokenizer=process.tokenizer, label_ids=label_ids, args=cfg)
model = PromptGeneratorModel(prompt_model=prompt_model, bos_token_id=0,
eos_token_id=1,
max_length=cfg.tgt_max_len, max_len_a=cfg.src_seq_ratio,num_beams=cfg.num_beams, do_sample=False,
repetition_penalty=1, length_penalty=cfg.length_penalty, pad_token_id=1,
restricter=None)
metrics = Seq2SeqSpanMetric(eos_token_id=1, num_labels=len(label_ids), target_type='word')
loss = get_loss
trainer = Trainer(train_data=train_dataloader, dev_data=dev_dataloader, test_data=None, model=model, args=cfg, logger=logger, loss=loss, metrics=metrics, writer=writer)
trainer.train()
writer.close()
if __name__ == "__main__":
main()