Skip to content
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

Update SeqClassification.cs #94

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Seq2SeqSharp/Applications/SeqClassification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,21 @@ public override List<NetworkResult> RunForwardOnSingleDevice(IComputeGraph compu
using var targetIdxTensor = computeGraph.Argmax(probs, 1);
float[] targetIdx = targetIdxTensor.ToWeightArray();
List<string> targetWords = m_modelMetaData.TgtVocab.ConvertIdsToString(targetIdx.ToList());

List<string> allWords = m_modelMetaData.TgtVocab.IndexToWord.Values.Select(s => s).ToList();
var combinedOutput = probs.ToWeightArray().Zip(allWords, (prob, word) => $"{word.PadRight(15)}: {prob,10:F8}");
Logger.WriteLine(Logger.Level.info, $"\nWrds w/Probs\n{string.Join("\n", combinedOutput)}");

nr.Output.Add(new List<List<string>>());

for (int k = 0; k < batchSize; k++)
{
nr.Output[0].Add(new List<string>());
nr.Output[0][k].Add(targetWords[k]);

// Fetch the corresponding probability for the predicted target index
float probAtTargetIdx = probs.GetWeightAt([0, (long)targetIdx[k]]);

nr.Output[0][k].Add($"{targetWords[k]} {probAtTargetIdx:F8}");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you could add a new field for probability at target idx, such as:

public List<List<List>> Output; // (beam_size, batch_size, seq_len)
public List<List<List>> ProbAtOutputIdx; // (beam_size, batch_size, seq_len)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I figured you would have a good idea on adding something. I'll see about adding it.

}
}

Expand Down
Loading