|
| 1 | +/** Copyright 2025 RWTH Aachen University. All rights reserved. |
| 2 | + * |
| 3 | + * Licensed under the RWTH ASR License (the "License"); |
| 4 | + * you may not use this file except in compliance with the License. |
| 5 | + * You may obtain a copy of the License at |
| 6 | + * |
| 7 | + * http://www.hltpr.rwth-aachen.de/rwth-asr/rwth-asr-license.html |
| 8 | + * |
| 9 | + * Unless required by applicable law or agreed to in writing, software |
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | + * See the License for the specific language governing permissions and |
| 13 | + * limitations under the License. |
| 14 | + */ |
| 15 | + |
| 16 | +#include "TransitionLabelScorer.hh" |
| 17 | + |
| 18 | +#include <Nn/Module.hh> |
| 19 | + |
| 20 | +namespace Nn { |
| 21 | + |
| 22 | +TransitionLabelScorer::TransitionLabelScorer(Core::Configuration const& config) |
| 23 | + : Core::Component(config), |
| 24 | + Precursor(config), |
| 25 | + transitionScores_(), |
| 26 | + baseLabelScorer_(Nn::Module::instance().labelScorerFactory().createLabelScorer(select("base-scorer"))) { |
| 27 | + for (auto const& [stringIdentifier, enumValue] : transitionTypeArray_) { |
| 28 | + auto paramName = std::string(stringIdentifier) + "-score"; |
| 29 | + transitionScores_[enumValue] = Core::ParameterFloat(paramName.c_str(), "", 0.0)(config); |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +void TransitionLabelScorer::reset() { |
| 34 | + baseLabelScorer_->reset(); |
| 35 | +} |
| 36 | + |
| 37 | +void TransitionLabelScorer::signalNoMoreFeatures() { |
| 38 | + baseLabelScorer_->signalNoMoreFeatures(); |
| 39 | +} |
| 40 | + |
| 41 | +ScoringContextRef TransitionLabelScorer::getInitialScoringContext() { |
| 42 | + return baseLabelScorer_->getInitialScoringContext(); |
| 43 | +} |
| 44 | + |
| 45 | +ScoringContextRef TransitionLabelScorer::extendedScoringContext(LabelScorer::Request const& request) { |
| 46 | + return baseLabelScorer_->extendedScoringContext(request); |
| 47 | +} |
| 48 | + |
| 49 | +void TransitionLabelScorer::cleanupCaches(Core::CollapsedVector<ScoringContextRef> const& activeContexts) { |
| 50 | + baseLabelScorer_->cleanupCaches(activeContexts); |
| 51 | +} |
| 52 | + |
| 53 | +void TransitionLabelScorer::addInput(DataView const& input) { |
| 54 | + baseLabelScorer_->addInput(input); |
| 55 | +} |
| 56 | + |
| 57 | +void TransitionLabelScorer::addInputs(DataView const& input, size_t nTimesteps) { |
| 58 | + baseLabelScorer_->addInputs(input, nTimesteps); |
| 59 | +} |
| 60 | + |
| 61 | +std::optional<LabelScorer::ScoreWithTime> TransitionLabelScorer::computeScoreWithTime(LabelScorer::Request const& request) { |
| 62 | + auto result = baseLabelScorer_->computeScoreWithTime(request); |
| 63 | + if (result) { |
| 64 | + result->score += transitionScores_[request.transitionType]; |
| 65 | + } |
| 66 | + return result; |
| 67 | +} |
| 68 | + |
| 69 | +std::optional<LabelScorer::ScoresWithTimes> TransitionLabelScorer::computeScoresWithTimes(std::vector<LabelScorer::Request> const& requests) { |
| 70 | + auto results = baseLabelScorer_->computeScoresWithTimes(requests); |
| 71 | + if (results) { |
| 72 | + for (size_t i = 0ul; i < requests.size(); ++i) { |
| 73 | + results->scores[i] += transitionScores_[requests[i].transitionType]; |
| 74 | + } |
| 75 | + } |
| 76 | + return results; |
| 77 | +} |
| 78 | + |
| 79 | +} // namespace Nn |
0 commit comments