Open JoshuaMathias opened 2 years ago
Answer to question 3:
From this error I see that s1 is meant to be a tuple of (text, length of text):
self = BLSTMEncoder(
(enc_lstm): LSTM(300, 100, num_layers=3, dropout=0.5, bidirectional=True)
)
sent_tuple = 'This is a sentence.'
def forward(self, sent_tuple):
# sent_len: [max_len, ..., min_len] (bsize)
# sent: Variable(seqlen x bsize x worddim)
> sent, sent_len = sent_tuple
E ValueError: too many values to unpack (expected 2)
It appears that scoring a new sentence involves the following:
word_vectors = {}
with open(word_vectors_path, encoding="utf8") as file:
for line in file:
word, vec = line.split(' ', 1)
if word:
word_vectors[word] = np.array(list(map(float, vec.split())))
I created a new function that does all the above on a list of sentence strings (the new __call__
function at generatefeatures.py: https://github.com/JoshuaMathias/Domain-Agnostic-Sentence-Specificity-Prediction/blob/master/generatefeatures.py), but I'm stuck at the last part where we get the actual specificity score. The paper describes normalizing ratings from 1-5 to 0-1, but I don't see this reflected in the code. When applying the model using the model's forward function, the output I'm getting is 26292.9473, 3277.1140 and the numbers are exactly the same for every sample text I gave it. If I use softmax like the code does in evaluate(), I get 1, 0, but my understanding is softmax is not useful at all here for getting the actual predicted value. Yet it's the output from softmax that is written in the evaluation code. I'm quite stumped.
@wjko2 How do we get the continuous value specificity score?
Update: I just reviewed the code for PDTBNet and found this:
self.classifier = nn.Sequential(
nn.Linear(self.inputdim, self.fc_dim),
nn.Linear(self.fc_dim, self.fc_dim),
nn.Linear(self.fc_dim, self.n_classes)
)
I realized from this that the last row of the model creates a relative continuous value for each class, where the default is set to 2. I used to think the n_classes parameter was just for the supervised training portion, which I guess this is. So now I understand the softmax operation as just normalizing the class values to be within 0 to 1 as a probability, and you use the class with the highest value as the specificity score.
It seems we best have 2 n_classes parameters: One for training data and one for the final output by the unsupervised model. But I only see one place in model output to choose the number of classes, which is the code I quoted above.
In my case I can convert all the training data to be the number of labels I want, which is 1 through 4 and have that be a consistent setting throughout, but since a main stated goal of the paper was to use data with 2 classes to train a model to produce a continuous value that could be used for more fine-grained ratings, I must be missing something. I think what I'm missing is understanding what in the code is supervised training vs unsupervised training.
@wjko2 How do I apply the model on a single new text? I don't understand the variable names in the arguments.
Here's what I tried:
This is the error I got:
I see this corresponding code in models.py for the class PDTBNet:
So, I can tell that I'm missing a second argument, but these are my questions: