diff --git a/fastNLP/models/sequence_modeling.py b/fastNLP/models/sequence_modeling.py index 80d13cf3..de6c2c66 100644 --- a/fastNLP/models/sequence_modeling.py +++ b/fastNLP/models/sequence_modeling.py @@ -3,7 +3,7 @@ import torch.nn as nn from torch.nn import functional as F from fastNLP.models.base_model import BaseModel -from fastNLP.modules.CRF import ContionalRandomField +from fastNLP.modules.decoder.CRF import ContionalRandomField class SeqLabeling(BaseModel): diff --git a/fastNLP/modules/attention/__init__.py b/fastNLP/modules/aggregation/__init__.py similarity index 100% rename from fastNLP/modules/attention/__init__.py rename to fastNLP/modules/aggregation/__init__.py diff --git a/fastNLP/modules/attention/attention.py b/fastNLP/modules/aggregation/attention.py similarity index 100% rename from fastNLP/modules/attention/attention.py rename to fastNLP/modules/aggregation/attention.py diff --git a/fastNLP/modules/convolution/avg_pool.py b/fastNLP/modules/aggregation/avg_pool.py similarity index 100% rename from fastNLP/modules/convolution/avg_pool.py rename to fastNLP/modules/aggregation/avg_pool.py diff --git a/fastNLP/modules/convolution/kmax_pool.py b/fastNLP/modules/aggregation/kmax_pool.py similarity index 100% rename from fastNLP/modules/convolution/kmax_pool.py rename to fastNLP/modules/aggregation/kmax_pool.py diff --git a/fastNLP/modules/attention/linear_attention.py b/fastNLP/modules/aggregation/linear_attention.py similarity index 78% rename from fastNLP/modules/attention/linear_attention.py rename to fastNLP/modules/aggregation/linear_attention.py index 0d34e205..8f761c7a 100644 --- a/fastNLP/modules/attention/linear_attention.py +++ b/fastNLP/modules/aggregation/linear_attention.py @@ -1,4 +1,4 @@ -from fastNLP.modules.attention.attention import Attention +from fastNLP.modules.aggregation.attention import Attention class LinearAttention(Attention): diff --git a/fastNLP/modules/convolution/max_pool.py b/fastNLP/modules/aggregation/max_pool.py similarity index 100% rename from fastNLP/modules/convolution/max_pool.py rename to fastNLP/modules/aggregation/max_pool.py diff --git a/fastNLP/modules/prototype/aggregation.py b/fastNLP/modules/aggregation/self_attention.py similarity index 94% rename from fastNLP/modules/prototype/aggregation.py rename to fastNLP/modules/aggregation/self_attention.py index 59e50e99..f3581b44 100644 --- a/fastNLP/modules/prototype/aggregation.py +++ b/fastNLP/modules/aggregation/self_attention.py @@ -2,7 +2,8 @@ import torch import torch.nn as nn from torch.autograd import Variable -class Selfattention(nn.Module): + +class SelfAttention(nn.Module): """ Self Attention Module. @@ -12,7 +13,7 @@ class Selfattention(nn.Module): r : the number of encoded vectors """ def __init__(self, input_size, d_a, r): - super(Selfattention, self).__init__() + super(SelfAttention, self).__init__() self.W_s1 = nn.Parameter(torch.randn(d_a, input_size), requires_grad=True) self.W_s2 = nn.Parameter(torch.randn(r, d_a), requires_grad=True) self.softmax = nn.Softmax(dim=2) diff --git a/fastNLP/modules/CRF.py b/fastNLP/modules/decoder/CRF.py similarity index 100% rename from fastNLP/modules/CRF.py rename to fastNLP/modules/decoder/CRF.py diff --git a/fastNLP/modules/convolution/__init__.py b/fastNLP/modules/decoder/__init__.py similarity index 100% rename from fastNLP/modules/convolution/__init__.py rename to fastNLP/modules/decoder/__init__.py diff --git a/fastNLP/modules/recurrent/__init__.py b/fastNLP/modules/encoder/__init__.py similarity index 100% rename from fastNLP/modules/recurrent/__init__.py rename to fastNLP/modules/encoder/__init__.py diff --git a/fastNLP/modules/convolution/conv.py b/fastNLP/modules/encoder/conv.py similarity index 100% rename from fastNLP/modules/convolution/conv.py rename to fastNLP/modules/encoder/conv.py diff --git a/fastNLP/modules/prototype/embedding.py b/fastNLP/modules/encoder/embedding.py similarity index 98% rename from fastNLP/modules/prototype/embedding.py rename to fastNLP/modules/encoder/embedding.py index 1ee88a92..17c8f20a 100644 --- a/fastNLP/modules/prototype/embedding.py +++ b/fastNLP/modules/encoder/embedding.py @@ -1,6 +1,6 @@ -import torch import torch.nn as nn + class Lookuptable(nn.Module): """ A simple lookup table @@ -19,5 +19,6 @@ class Lookuptable(nn.Module): def forward(self, x): return self.embed(x) + if __name__ == "__main__": model = Lookuptable(10, 20) diff --git a/fastNLP/modules/prototype/encoder.py b/fastNLP/modules/encoder/lstm.py similarity index 83% rename from fastNLP/modules/prototype/encoder.py rename to fastNLP/modules/encoder/lstm.py index 142496e1..6d110fca 100644 --- a/fastNLP/modules/prototype/encoder.py +++ b/fastNLP/modules/encoder/lstm.py @@ -1,6 +1,6 @@ -import torch import torch.nn as nn + class Lstm(nn.Module): """ LSTM module @@ -14,8 +14,8 @@ class Lstm(nn.Module): """ def __init__(self, input_size, hidden_size, num_layers, dropout, bidirectional): super(Lstm, self).__init__() - self.lstm = nn.LSTM(input_size, hidden_size, num_layers, bias=True, batch_first=True,\ - dropout=dropout, bidirectional=bidirectional) + self.lstm = nn.LSTM(input_size, hidden_size, num_layers, bias=True, batch_first=True, + dropout=dropout, bidirectional=bidirectional) def forward(self, x): x, _ = self.lstm(x) diff --git a/fastNLP/modules/interaction/__init__.py b/fastNLP/modules/interaction/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/fastNLP/modules/prototype/README.md b/reproduction/LSTM+self_attention_sentiment_analysis/README.md similarity index 100% rename from fastNLP/modules/prototype/README.md rename to reproduction/LSTM+self_attention_sentiment_analysis/README.md diff --git a/fastNLP/modules/prototype/Word2Idx.py b/reproduction/LSTM+self_attention_sentiment_analysis/Word2Idx.py similarity index 100% rename from fastNLP/modules/prototype/Word2Idx.py rename to reproduction/LSTM+self_attention_sentiment_analysis/Word2Idx.py diff --git a/fastNLP/modules/prototype/dataloader.py b/reproduction/LSTM+self_attention_sentiment_analysis/dataloader.py similarity index 99% rename from fastNLP/modules/prototype/dataloader.py rename to reproduction/LSTM+self_attention_sentiment_analysis/dataloader.py index af5cd8b8..dd7fc4f8 100644 --- a/fastNLP/modules/prototype/dataloader.py +++ b/reproduction/LSTM+self_attention_sentiment_analysis/dataloader.py @@ -1,9 +1,10 @@ -import random import pickle +import random + import torch -import numpy as np from torch.autograd import Variable + def float_wrapper(x, requires_grad=True, using_cuda=True): """ transform float type list to pytorch variable diff --git a/fastNLP/modules/prototype/example.py b/reproduction/LSTM+self_attention_sentiment_analysis/example.py similarity index 100% rename from fastNLP/modules/prototype/example.py rename to reproduction/LSTM+self_attention_sentiment_analysis/example.py diff --git a/fastNLP/modules/prototype/predict.py b/reproduction/LSTM+self_attention_sentiment_analysis/predict.py similarity index 95% rename from fastNLP/modules/prototype/predict.py rename to reproduction/LSTM+self_attention_sentiment_analysis/predict.py index d5346c0e..31affeb7 100644 --- a/fastNLP/modules/prototype/predict.py +++ b/reproduction/LSTM+self_attention_sentiment_analysis/predict.py @@ -1,4 +1,3 @@ -import torch import torch.nn as nn import torch.nn.functional as F diff --git a/fastNLP/modules/prototype/prepare.py b/reproduction/LSTM+self_attention_sentiment_analysis/prepare.py similarity index 99% rename from fastNLP/modules/prototype/prepare.py rename to reproduction/LSTM+self_attention_sentiment_analysis/prepare.py index 02fd19c5..b8f8d7b8 100644 --- a/fastNLP/modules/prototype/prepare.py +++ b/reproduction/LSTM+self_attention_sentiment_analysis/prepare.py @@ -1,6 +1,8 @@ import pickle + import Word2Idx + def get_sets(m, n): """ get a train set containing m samples and a test set containing n samples