-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added multiseq and multiclas task-types and several bug fixes
- Loading branch information
1 parent
51165e8
commit 9874a41
Showing
22 changed files
with
458 additions
and
120 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
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,32 @@ | ||
import torch | ||
|
||
|
||
class MultiAccuracy(): | ||
def __init__(self): | ||
self.cor = 0 | ||
self.total = 0 | ||
self.str = 'multi-acc.' | ||
|
||
def score(self, preds, golds, mask, vocabulary): | ||
# TODO: can this be done more efficient? | ||
if len(preds.shape) == 3: | ||
for sent_idx in range(len(mask)): | ||
for word_idx in range(len(mask[sent_idx])): | ||
if mask[sent_idx][word_idx]: | ||
if torch.all(preds[sent_idx][word_idx] == golds[sent_idx][word_idx]): | ||
self.cor += 1 | ||
self.total += 1 | ||
if len(preds.shape) == 2: | ||
for sent_idx in range(len(preds)): | ||
if torch.all(preds[sent_idx] == golds[sent_idx]): | ||
self.cor += 1 | ||
self.total += 1 | ||
|
||
def reset(self): | ||
self.cor = 0 | ||
self.total = 0 | ||
|
||
def get_score(self): | ||
if self.total == 0: | ||
return self.str, 0.0 | ||
return self.str, self.cor / self.total |
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.