Download tools/mosesdecoder/moses/FF/Factory.cpp from Quagmire1/wiki-cased: direct link, hf CLI and curl.
- Browser
- Download file 13.4 kB
-
https://huggingface.co/Quagmire1/wiki-cased/resolve/main/tools/mosesdecoder/moses/FF/Factory.cpp
- Command line
-
hf download hf://Quagmire1/wiki-cased/tools/mosesdecoder/moses/FF/Factory.cpp
-
curl -L -o Factory.cpp https://huggingface.co/Quagmire1/wiki-cased/resolve/main/tools/mosesdecoder/moses/FF/Factory.cpp
13.4 kB
| namespace Moses | |
| { | |
| class FeatureFactory | |
| { | |
| public: | |
| virtual ~FeatureFactory() {} | |
| virtual void Create(const std::string &line) = 0; | |
| protected: | |
| template <class F> static void DefaultSetup(F *feature); | |
| FeatureFactory() {} | |
| }; | |
| template <class F> | |
| void | |
| FeatureFactory | |
| ::DefaultSetup(F *feature) | |
| { | |
| FeatureFunction::Register(feature); | |
| StaticData &static_data = StaticData::InstanceNonConst(); | |
| const std::string &featureName = feature->GetScoreProducerDescription(); | |
| std::vector<float> weights = static_data.GetParameter()->GetWeights(featureName); | |
| if (feature->GetNumScoreComponents()) { | |
| if (weights.size() == 0) { | |
| weights = feature->DefaultWeights(); | |
| if (weights.size() == 0) { | |
| TRACE_ERR("WARNING: No weights specified in config file for FF " | |
| << featureName << ". This FF does not supply default values.\n" | |
| << "WARNING: Auto-initializing all weights for this FF to 1.0"); | |
| weights.assign(feature->GetNumScoreComponents(),1.0); | |
| } else { | |
| VERBOSE(2,"WARNING: No weights specified in config file for FF " | |
| << featureName << ". Using default values supplied by FF."); | |
| } | |
| } | |
| UTIL_THROW_IF2(weights.size() != feature->GetNumScoreComponents(), | |
| "FATAL ERROR: Mismatch in number of features and number " | |
| << "of weights for Feature Function " << featureName | |
| << " (features: " << feature->GetNumScoreComponents() | |
| << " vs. weights: " << weights.size() << ")"); | |
| static_data.SetWeights(feature, weights); | |
| } else if (feature->IsTuneable()) | |
| static_data.SetWeights(feature, weights); | |
| } | |
| namespace | |
| { | |
| template <class F> | |
| class DefaultFeatureFactory : public FeatureFactory | |
| { | |
| public: | |
| void Create(const std::string &line) { | |
| DefaultSetup(new F(line)); | |
| } | |
| }; | |
| class KenFactory : public FeatureFactory | |
| { | |
| public: | |
| void Create(const std::string &line) { | |
| DefaultSetup(ConstructKenLM(line)); | |
| } | |
| }; | |
| class ReloadingFactory : public FeatureFactory | |
| { | |
| public: | |
| void Create(const std::string &line) { | |
| DefaultSetup(ConstructReloadingLM(line)); | |
| } | |
| }; | |
| } // namespace | |
| FeatureRegistry::FeatureRegistry() | |
| { | |
| // Feature with same name as class | |
| // Feature with different name than class. | |
| MOSES_FNAME2("PhraseDictionaryBinary", PhraseDictionaryTreeAdaptor); | |
| MOSES_FNAME(PhraseDictionaryOnDisk); | |
| MOSES_FNAME(PhraseDictionaryMemory); | |
| MOSES_FNAME(PhraseDictionaryScope3); | |
| MOSES_FNAME(PhraseDictionaryMultiModel); | |
| MOSES_FNAME(PhraseDictionaryMultiModelCounts); | |
| MOSES_FNAME(PhraseDictionaryGroup); | |
| MOSES_FNAME(PhraseDictionaryALSuffixArray); | |
| // MOSES_FNAME(PhraseDictionaryDynSuffixArray); | |
| MOSES_FNAME(PhraseDictionaryTransliteration); | |
| MOSES_FNAME(PhraseDictionaryDynamicCacheBased); | |
| MOSES_FNAME(PhraseDictionaryCache); | |
| MOSES_FNAME(PhraseDictionaryFuzzyMatch); | |
| MOSES_FNAME(ProbingPT); | |
| MOSES_FNAME(PhraseDictionaryMemoryPerSentence); | |
| MOSES_FNAME(PhraseDictionaryMemoryPerSentenceOnDemand); | |
| MOSES_FNAME2("RuleTable", Syntax::RuleTableFF); | |
| MOSES_FNAME2("SyntaxInputWeight", Syntax::InputWeightFF); | |
| MOSES_FNAME(GlobalLexicalModel); | |
| //MOSES_FNAME(GlobalLexicalModelUnlimited); This was commented out in the original | |
| MOSES_FNAME(Model1Feature); | |
| MOSES_FNAME(SourceWordDeletionFeature); | |
| MOSES_FNAME(TargetWordInsertionFeature); | |
| MOSES_FNAME(PhraseBoundaryFeature); | |
| MOSES_FNAME(PhraseDistanceFeature); | |
| MOSES_FNAME(PhraseLengthFeature); | |
| MOSES_FNAME(WordTranslationFeature); | |
| MOSES_FNAME(TargetBigramFeature); | |
| MOSES_FNAME(TargetNgramFeature); | |
| MOSES_FNAME(PhrasePairFeature); | |
| MOSES_FNAME(RulePairUnlexicalizedSource); | |
| MOSES_FNAME(LexicalReordering); | |
| MOSES_FNAME2("Generation", GenerationDictionary); | |
| MOSES_FNAME(BleuScoreFeature); | |
| MOSES_FNAME2("Distortion", DistortionScoreProducer); | |
| MOSES_FNAME2("WordPenalty", WordPenaltyProducer); | |
| MOSES_FNAME(InputFeature); | |
| MOSES_FNAME(OpSequenceModel); | |
| MOSES_FNAME(DesegModel); | |
| MOSES_FNAME(PhrasePenalty); | |
| MOSES_FNAME2("UnknownWordPenalty", UnknownWordPenaltyProducer); | |
| MOSES_FNAME(ControlRecombination); | |
| MOSES_FNAME(ConstrainedDecoding); | |
| MOSES_FNAME(CoveredReferenceFeature); | |
| MOSES_FNAME(SourceGHKMTreeInputMatchFeature); | |
| MOSES_FNAME(SoftSourceSyntacticConstraintsFeature); | |
| MOSES_FNAME(TargetConstituentAdjacencyFeature); | |
| MOSES_FNAME(TargetPreferencesFeature); | |
| MOSES_FNAME(TreeStructureFeature); | |
| MOSES_FNAME(SoftMatchingFeature); | |
| MOSES_FNAME(DynamicCacheBasedLanguageModel); | |
| MOSES_FNAME(HyperParameterAsWeight); | |
| MOSES_FNAME(SetSourcePhrase); | |
| MOSES_FNAME(CountNonTerms); | |
| MOSES_FNAME(ReferenceComparison); | |
| MOSES_FNAME(RuleScope); | |
| MOSES_FNAME(MaxSpanFreeNonTermSource); | |
| MOSES_FNAME(NieceTerminal); | |
| MOSES_FNAME(SparseHieroReorderingFeature); | |
| MOSES_FNAME(SpanLength); | |
| MOSES_FNAME(SyntaxRHS); | |
| MOSES_FNAME(PhraseOrientationFeature); | |
| MOSES_FNAME(UnalignedWordCountFeature); | |
| MOSES_FNAME(DeleteRules); | |
| MOSES_FNAME(ExampleStatelessFF); | |
| MOSES_FNAME(ExampleStatefulFF); | |
| MOSES_FNAME(ExampleLM); | |
| MOSES_FNAME(ExampleTranslationOptionListFeature); | |
| MOSES_FNAME(ExamplePT); | |
| MOSES_FNAME(InMemoryPerSentenceOnDemandLM); | |
| MOSES_FNAME(EditOps); | |
| MOSES_FNAME(CorrectionPattern); | |
| MOSES_FNAME(VW); | |
| MOSES_FNAME(VWFeatureContextBigrams); | |
| MOSES_FNAME(VWFeatureContextBilingual); | |
| MOSES_FNAME(VWFeatureContextWindow); | |
| MOSES_FNAME(VWFeatureSourceBagOfWords); | |
| MOSES_FNAME(VWFeatureSourceBigrams); | |
| MOSES_FNAME(VWFeatureSourceIndicator); | |
| MOSES_FNAME(VWFeatureSourcePhraseInternal); | |
| MOSES_FNAME(VWFeatureSourceSenseWindow); | |
| MOSES_FNAME(VWFeatureSourceWindow); | |
| MOSES_FNAME(VWFeatureTargetBigrams); | |
| MOSES_FNAME(VWFeatureTargetPhraseInternal); | |
| MOSES_FNAME(VWFeatureTargetIndicator); | |
| MOSES_FNAME(VWFeatureSourceExternalFeatures); | |
| MOSES_FNAME(VWFeatureTargetPhraseScores); | |
| MOSES_FNAME(PhraseDictionaryCompact); | |
| MOSES_FNAME(Mmsapt); | |
| MOSES_FNAME2("PhraseDictionaryBitextSampling",Mmsapt); // that's an alias for Mmsapt! | |
| MOSES_FNAME(SyntacticLanguageModel); | |
| MOSES_FNAME2("IRSTLM", LanguageModelIRST); | |
| MOSES_FNAME2("SRILM", LanguageModelSRI); | |
| MOSES_FNAME2("MaxEntLM", LanguageModelMaxEntSRI); | |
| MOSES_FNAME2("RANDLM", LanguageModelRandLM); | |
| MOSES_FNAME2("NeuralLM", NeuralLMWrapper); | |
| MOSES_FNAME(RDLM); | |
| MOSES_FNAME2("BilingualNPLM", BilingualLM_NPLM); | |
| MOSES_FNAME2("DALM", LanguageModelDALM); | |
| MOSES_FNAME2("OxLM", OxLM<oxlm::LM>); | |
| MOSES_FNAME2("OxFactoredLM", OxLM<oxlm::FactoredLM>); | |
| MOSES_FNAME2("OxFactoredMaxentLM", OxLM<oxlm::FactoredMaxentLM>); | |
| MOSES_FNAME2("OxSourceFactoredLM", SourceOxLM); | |
| MOSES_FNAME2("OxTreeLM", OxLM<oxlm::FactoredTreeLM>); | |
| Add("ReloadingLM", new ReloadingFactory()); | |
| Add("KENLM", new KenFactory()); | |
| } | |
| FeatureRegistry::~FeatureRegistry() | |
| { | |
| } | |
| void FeatureRegistry::Add(const std::string &name, FeatureFactory *factory) | |
| { | |
| std::pair<std::string, boost::shared_ptr<FeatureFactory> > to_ins(name, boost::shared_ptr<FeatureFactory>(factory)); | |
| UTIL_THROW_IF2(!registry_.insert(to_ins).second, "Duplicate feature name " << name); | |
| } | |
| namespace | |
| { | |
| class UnknownFeatureException : public util::Exception {}; | |
| } | |
| void FeatureRegistry::Construct(const std::string &name, const std::string &line) | |
| { | |
| Map::iterator i = registry_.find(name); | |
| UTIL_THROW_IF(i == registry_.end(), UnknownFeatureException, "Feature name " << name << " is not registered."); | |
| i->second->Create(line); | |
| } | |
| void FeatureRegistry::PrintFF() const | |
| { | |
| std::vector<std::string> ffs; | |
| std::cerr << "Available feature functions:" << std::endl; | |
| Map::const_iterator iter; | |
| for (iter = registry_.begin(); iter != registry_.end(); ++iter) { | |
| const std::string &ffName = iter->first; | |
| ffs.push_back(ffName); | |
| } | |
| std::vector<std::string>::const_iterator iterVec; | |
| std::sort(ffs.begin(), ffs.end()); | |
| for (iterVec = ffs.begin(); iterVec != ffs.end(); ++iterVec) { | |
| const std::string &ffName = *iterVec; | |
| std::cerr << ffName << " "; | |
| } | |
| std::cerr << std::endl; | |
| } | |
| } // namespace Moses | |