This repository has been archived by the owner on Aug 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6809ade
commit d7cb516
Showing
10 changed files
with
83 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#encoding: utf-8 |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#encoding: utf-8 | ||
|
||
''' usage: | ||
python tools/add_tag.py $src_file.t7 $rs_file.t7 $token | ||
''' | ||
|
||
import sys | ||
|
||
def handle(srcf, rsf, token): | ||
|
||
_et = token.encode("utf-8") if token.endswith(" ") else (token + " ").encode("utf-8") | ||
_ens = "\n".encode("utf-8") | ||
|
||
with open(srcf, "rb") as frd, open(rsf, "wb") as fwrt: | ||
for line in frd: | ||
tmp = line.strip() | ||
if tmp: | ||
tmp = tmp.decode("utf-8") | ||
fwrt.write(_et) | ||
fwrt.write(tmp.encode("utf-8")) | ||
fwrt.write(_ens) | ||
|
||
if __name__ == "__main__": | ||
handle(sys.argv[1], sys.argv[2], sys.argv[3]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#encoding: utf-8 | ||
|
||
''' usage: | ||
python remove_layers.py $src.t7 $rs.t7 enc/dec layers... | ||
''' | ||
|
||
import sys | ||
|
||
import torch | ||
from torch.nn import ModuleList | ||
|
||
from transformer.NMT import NMT | ||
|
||
from utils import * | ||
|
||
import h5py | ||
import cnfg | ||
|
||
def handle(srcf, rsf, typ, rlist): | ||
|
||
td = h5py.File(cnfg.dev_data, "r") | ||
nwordi = int(td["nwordi"][:][0]) | ||
nwordt = int(td["nwordt"][:][0]) | ||
td.close() | ||
|
||
_tmpm = NMT(cnfg.isize, nwordi, nwordt, cnfg.nlayer, cnfg.ff_hsize, cnfg.drop, cnfg.attn_drop, cnfg.share_emb, cnfg.nhead, cnfg.cache_len, cnfg.attn_hsize, cnfg.norm_output, cnfg.bindDecoderEmb, cnfg.forbidden_indexes) | ||
_tmpm = load_model_cpu(srcf, _tmpm) | ||
if typ == "enc": | ||
_tmpm.enc.nets = ModuleList(remove_layers(list(_tmpm.enc.nets), rlist)) | ||
elif typ == "dec": | ||
_tmpm.dec.nets = ModuleList(remove_layers(list(_tmpm.dec.nets), rlist)) | ||
|
||
save_model(_tmpm, rsf, False) | ||
|
||
if __name__ == "__main__": | ||
handle(sys.argv[1], sys.argv[2], sys.argv[3], [int(_t) for _t in sys.argv[4:]]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters