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
Showing
15 changed files
with
668 additions
and
33 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,29 @@ | ||
#encoding: utf-8 | ||
|
||
from math import sqrt, log, exp, pi | ||
import torch | ||
from torch import nn | ||
from torch.nn import functional as nnFunc | ||
from torch.autograd import Function | ||
|
||
from modules import GeLU_BERT | ||
from modules import PositionwiseFF as PositionwiseFFBase | ||
|
||
class PositionwiseFF(PositionwiseFFBase): | ||
|
||
# isize: input dimension | ||
# hsize: hidden dimension | ||
|
||
def __init__(self, isize, hsize=None, dropout=0.0, use_GeLU=False): | ||
|
||
super(PositionwiseFF, self).__init__(isize, hsize, dropout, False, use_GeLU) | ||
|
||
def forward(self, x): | ||
|
||
out = x | ||
for net in self.nets: | ||
out = net(out) | ||
|
||
out = self.normer(out + x) | ||
|
||
return out |
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
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
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 | ||
|
||
import sys | ||
|
||
def handle(srcfs, srtsf, srttf, tgtf): | ||
|
||
def clean(lin): | ||
rs = [] | ||
for lu in lin.split(): | ||
if lu: | ||
rs.append(lu) | ||
return " ".join(rs), len(rs) | ||
|
||
data = {} | ||
|
||
with open(srtsf, "rb") as fs, open(srttf, "rb") as ft: | ||
for sl, tl in zip(fs, ft): | ||
_sl, _tl = sl.strip(), tl.strip() | ||
if _sl and _tl: | ||
_sl, _ls = clean(_sl.decode("utf-8")) | ||
_tl, _lt = clean(_tl.decode("utf-8")) | ||
data[_sl] = _tl | ||
|
||
ens = "\n".encode("utf-8") | ||
|
||
with open(srcfs, "rb") as fs, open(tgtf, "wb") as ft: | ||
for line in fs: | ||
tmp = line.strip() | ||
if tmp: | ||
tmp, _ = clean(tmp.decode("utf-8")) | ||
tmp = data.get(tmp, "") | ||
ft.write(tmp.encode("utf-8")) | ||
ft.write(ens) | ||
|
||
if __name__ == "__main__": | ||
handle(sys.argv[1], sys.argv[2], sys.argv[3], 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#encoding: utf-8 | ||
|
||
import sys | ||
|
||
def handle(srcfs, tgtfs): | ||
|
||
def clean(lin): | ||
rs = [] | ||
for lu in lin: | ||
if lu: | ||
rs.append(lu) | ||
return " ".join(rs), len(rs) | ||
|
||
data = {} | ||
|
||
with open(srcfs, "rb") as fs: | ||
for ls in fs: | ||
ls = ls.strip() | ||
if ls: | ||
ls, lgth = clean(ls.decode("utf-8").split()) | ||
if lgth not in data: | ||
data[lgth] = set([ls]) | ||
else: | ||
if ls not in data[lgth]: | ||
data[lgth].add(ls) | ||
|
||
length = list(data.keys()) | ||
length.sort() | ||
|
||
ens = "\n".encode("utf-8") | ||
|
||
with open(tgtfs, "wb") as fs: | ||
for lgth in length: | ||
fs.write("\n".join(data[lgth]).encode("utf-8")) | ||
fs.write(ens) | ||
|
||
if __name__ == "__main__": | ||
handle(sys.argv[1], sys.argv[2]) |
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
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
Oops, something went wrong.