-
Notifications
You must be signed in to change notification settings - Fork 305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Multi round nbest rescoring #5
Conversation
icefall/decode.py
Outdated
est_scores = 1 - 1/2 * ( | ||
1 + torch.erf( | ||
(best_score - path_mean) / torch.sqrt(2 * path_var) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For finding the best path, instead of trying to use this kind of integral, I would use:
(path_mean - best_score) / torch.sqrt(path_var)
which can be interpreted as the "z score". This has a monotonic relationship with this percentile/integral thingy, and is easier to compute and better behaved numerically.
After fixing some errors, now I can get the same WER (as original attention decoder) using nbest attention rescoring, see the table below:
The future plans are:
|
self, | ||
path: Path, | ||
model: str, | ||
) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add documentations to the methods/functions in this file?
import glob | ||
import logging | ||
from pathlib import Path | ||
from typing import Tuple, List |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you have a look at
https://icefall.readthedocs.io/en/latest/contributing/code-style.html
to follow the code style?
self.files = files[0: int(len(files) * 0.8)] | ||
elif model == 'dev': | ||
self.files = files[int(len(files) * 0.8): int(len(files) * 0.9)] | ||
elif mode == 'test': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mode
or model
?
x = self.embedding(x) | ||
x = self.sigmod(x) | ||
x = self.output(x) | ||
mean, var = x[:, 0], x[:, 1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var
-> log_var
?
"--hidden-dim", | ||
type=int, | ||
default=20, | ||
help="Neural number of didden layer.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
help="Neural number of didden layer.", | |
help="Neural number of hidden layer.", |
hidden_dim = args.hidden_dim | ||
) | ||
|
||
model = model.to("cuda") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we support also CPU?
step = 0 | ||
model.eval() | ||
for x, y in dev_dataloader: | ||
mean, var = model(x.cuda()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would recommend you to define a variable device
, which can be either a CPU or a CUDA device, and use model(x.to(device))
.
dev_loss = 0.0 | ||
step = 0 | ||
model.eval() | ||
for x, y in dev_dataloader: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please put the evaluation process in a context disabling gradient computation.
import torch | ||
import torch.nn as nn | ||
from torch.utils.data import DataLoader | ||
from torch.utils.tensorboard import SummaryWriter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove unused imports.
If you have a look at https://icefall.readthedocs.io/en/latest/contributing/code-style.html
and start to use flake8
, it will tell you this import is never used.
parser = get_parser() | ||
args = parser.parse_args() | ||
torch.manual_seed(42) | ||
torch.cuda.manual_seed(42) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
torch.cuda.manual_seed(42) |
torch.manual_seed(42)
already did it.
There are several decoding methods in icefall now, their pipelines are demonstrated as the picture below. What I want to do in this pull request locates in the red rectangle, it was proposed here(k2-fsa/snowfall#232) several weeks ago.
This is just at the very beginning, just copy the related previous work from k2 & snowfall.