Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
7502b82
Add TransitionLabelScorer
SimBe195 Jul 24, 2025
7430001
Rewrite docstring
SimBe195 Jul 24, 2025
2a6272e
Clean up includes
SimBe195 Jul 24, 2025
7e325e1
Rewrite docstring again
SimBe195 Jul 24, 2025
a276136
Merge branch 'master' into tdp_label_scorer
SimBe195 Sep 24, 2025
d2d78fe
Refactor params to string list with compile time check
SimBe195 Sep 24, 2025
303fa46
Remove transitionTypeToIndex function and revert associated changes
SimBe195 Sep 24, 2025
ddd75c7
Revert unnecessary static_cast
SimBe195 Sep 24, 2025
b856c1e
Change std=c++17 to c++20
SimBe195 Sep 30, 2025
70699c0
Merge remote-tracking branch 'origin/version-bump' into tdp_label_scorer
SimBe195 Sep 30, 2025
5b89d0f
Move transition type string array to LabelScorer.hh
SimBe195 Sep 30, 2025
8b27b19
Add parameter for ignoring transition types in LabelScorer
SimBe195 Oct 1, 2025
1e877c7
Add missing parenthesis in description
SimBe195 Oct 1, 2025
3dcadee
Add some docstrings for the `Internal` functions
SimBe195 Oct 1, 2025
b9d919b
Move transitionTypeArray to protected space
SimBe195 Oct 1, 2025
23df463
Merge branch 'tdp_label_scorer' into disabled-transition-types
SimBe195 Oct 1, 2025
a437c04
Merge branch 'master' into disabled-transition-types
curufinwe Oct 8, 2025
8337fea
Fix order in .cc files
curufinwe Oct 9, 2025
0cfdf3d
Add `set` function to Core::CollapsedVector
SimBe195 Oct 10, 2025
85522b5
Apply suggestions from code review
SimBe195 Oct 10, 2025
4098ad4
Fix compilation
SimBe195 Oct 10, 2025
0d34085
Introduce configurable presets of enabled transition types + extras
SimBe195 Oct 10, 2025
a186d3d
Make TransitionLabelScorer standalone
larissakl Oct 20, 2025
f068d03
Formatting
larissakl Oct 20, 2025
5cb1caf
Merge branch 'master' into transition-label-scorer-standalone
larissakl Nov 5, 2025
9409db4
Use base class ScoringContext instead of StepScoringContext
larissakl Nov 5, 2025
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
43 changes: 13 additions & 30 deletions src/Nn/LabelScorer/TransitionLabelScorer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,47 +22,31 @@ namespace Nn {
TransitionLabelScorer::TransitionLabelScorer(Core::Configuration const& config)
: Core::Component(config),
Precursor(config, TransitionPresetType::ALL),
transitionScores_(),
baseLabelScorer_(Nn::Module::instance().labelScorerFactory().createLabelScorer(select("base-scorer"))) {
transitionScores_() {
for (auto const& [stringIdentifier, enumValue] : transitionTypeArray_) {
auto paramName = std::string(stringIdentifier) + "-score";
transitionScores_[enumValue] = Core::ParameterFloat(paramName.c_str(), "", 0.0)(config);
}
}

void TransitionLabelScorer::reset() {
baseLabelScorer_->reset();
}
void TransitionLabelScorer::reset() {}

void TransitionLabelScorer::signalNoMoreFeatures() {
baseLabelScorer_->signalNoMoreFeatures();
}
void TransitionLabelScorer::signalNoMoreFeatures() {}

ScoringContextRef TransitionLabelScorer::getInitialScoringContext() {
return baseLabelScorer_->getInitialScoringContext();
}

void TransitionLabelScorer::cleanupCaches(Core::CollapsedVector<ScoringContextRef> const& activeContexts) {
baseLabelScorer_->cleanupCaches(activeContexts);
return Core::ref(new ScoringContext());
}

void TransitionLabelScorer::addInput(DataView const& input) {
baseLabelScorer_->addInput(input);
}

void TransitionLabelScorer::addInputs(DataView const& input, size_t nTimesteps) {
baseLabelScorer_->addInputs(input, nTimesteps);
}
void TransitionLabelScorer::addInput(DataView const& input) {}

ScoringContextRef TransitionLabelScorer::extendedScoringContextInternal(LabelScorer::Request const& request) {
return baseLabelScorer_->extendedScoringContext(request);
return Core::ref(new ScoringContext());
}

std::optional<LabelScorer::ScoreWithTime> TransitionLabelScorer::computeScoreWithTimeInternal(LabelScorer::Request const& request) {
auto result = baseLabelScorer_->computeScoreWithTime(request);
if (result) {
result->score += transitionScores_[request.transitionType];
}
LabelScorer::ScoreWithTime result;
result.score = transitionScores_[request.transitionType];
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is the timeframe initialized with 0?
Should it be for example currentStep of StepScoringContext class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't really use a scoring context in this label scorer and therefore have no information about the current timestep. LabelScorer::ScoreWithTime however needs a timeframe. Therefore I just set it to 0 because it is not used anyways. When using the TransitionLabelScorer in combination with another label scorer in the CombineLabelScorer, the maximum of both timesteps will be used for the result, so 0 won't break anything.

result.timeframe = static_cast<Speech::TimeframeIndex>(0);
return result;
}

Expand All @@ -71,11 +55,10 @@ std::optional<LabelScorer::ScoresWithTimes> TransitionLabelScorer::computeScores
return ScoresWithTimes{};
}

auto results = baseLabelScorer_->computeScoresWithTimes(requests);
if (results) {
for (size_t i = 0ul; i < requests.size(); ++i) {
results->scores[i] += transitionScores_[requests[i].transitionType];
}
LabelScorer::ScoresWithTimes results;
for (size_t i = 0ul; i < requests.size(); ++i) {
results.scores.push_back(transitionScores_[requests[i].transitionType]);
results.timeframes.push_back(static_cast<Speech::TimeframeIndex>(0));
}
return results;
}
Expand Down
26 changes: 9 additions & 17 deletions src/Nn/LabelScorer/TransitionLabelScorer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
namespace Nn {

/*
* This LabelScorer wraps a base LabelScorer and adds predefined transition scores
* to the base scores depending on the transition type of each request.
* This LabelScorer returns predefined transition scores depending on the transition type of each request.
* The transition scores are all individually specified as config parameters.
* It should be used together with a main LabelScorer within the CombineLabelScorer
*/
class TransitionLabelScorer : public LabelScorer {
public:
Expand All @@ -32,38 +32,30 @@ public:
TransitionLabelScorer(Core::Configuration const& config);
virtual ~TransitionLabelScorer() = default;

// Reset base scorer
// No op
void reset() override;

// Forward signal to base scorer
// No op
void signalNoMoreFeatures() override;

// Initial context of base scorer
// Return dummy-context
ScoringContextRef getInitialScoringContext() override;

// Clean up base scorer
void cleanupCaches(Core::CollapsedVector<ScoringContextRef> const& activeContexts) override;

// Add input to base scorer
// No op
void addInput(DataView const& input) override;

// Add inputs to sub-scorer
void addInputs(DataView const& input, size_t nTimesteps) override;

protected:
// Extend context via base scorer
// Return dummy-context
ScoringContextRef extendedScoringContextInternal(Request const& request) override;

// Compute score of base scorer and add transition score based on transition type of the request
// Return transition score based on transition type of the request
std::optional<ScoreWithTime> computeScoreWithTimeInternal(Request const& request) override;

// Compute scores of base scorer and add transition scores based on transition types of the requests
// Return transition scores based on transition types of the requests
std::optional<ScoresWithTimes> computeScoresWithTimesInternal(std::vector<Request> const& requests) override;

private:
std::unordered_map<TransitionType, Score> transitionScores_;

Core::Ref<LabelScorer> baseLabelScorer_;
};

} // namespace Nn
Expand Down