Package org.languagetool.rules
Class BERTSuggestionRanking
java.lang.Object
org.languagetool.rules.Rule
org.languagetool.rules.RemoteRule
org.languagetool.rules.BERTSuggestionRanking
reorder suggestions from another rule using BERT as a LM
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class(package private) static classNested classes/interfaces inherited from class org.languagetool.rules.RemoteRule
RemoteRule.RemoteRequest -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final org.slf4j.Loggerprivate static final doubleprivate static final intprivate final RemoteLanguageModelprivate static final com.google.common.cache.LoadingCache<RemoteRuleConfig, RemoteLanguageModel> static final Stringprotected intprivate final RuleFields inherited from class org.languagetool.rules.RemoteRule
circuitBreakers, filterMatches, fixOffsets, inputLogging, lt, premium, ruleLanguage, serviceConfiguration, shutdownRoutines, suppressMisspelledMatch, suppressMisspelledSuggestions, whitespaceNormalisation -
Constructor Summary
ConstructorsConstructorDescriptionBERTSuggestionRanking(Language language, Rule rule, RemoteRuleConfig config, boolean inputLogging) -
Method Summary
Modifier and TypeMethodDescriptionprivate RemoteLanguageModel.RequestbuildRequest(RuleMatch match) protected Callable<RemoteRuleResult> executeRequest(RemoteRule.RemoteRequest request, long timeoutMilliseconds) protected RemoteRuleResultfallbackResults(RemoteRule.RemoteRequest request) fallback if executeRequest times out or throws an errorA short description of the error this rule can detect, usually in the language of the text that is checked.getId()A string used to identify the rule in e.g.protected RemoteRule.RemoteRequestprepareRequest(List<AnalyzedSentence> sentences, Long textSessionId) run local preprocessing steps (or just store sentences)protected List<SuggestedReplacement> prepareSuggestions(List<SuggestedReplacement> suggestions) transform suggestions before resorting, e.g.Methods inherited from class org.languagetool.rules.RemoteRule
circuitBreaker, computeOffsetShifts, createCircuitBreaker, fixMatchOffsets, getCircuitBreakerConfig, getServiceConfiguration, getTimeout, getTimeout, isPremium, match, run, run, shutdownMethods inherited from class org.languagetool.rules.Rule
addExamplePair, addTags, addToneTags, cacheAntiPatterns, estimateContextForSureMatch, getAntiPatterns, getCategory, getCorrectExamples, getDistanceTokens, getErrorTriggeringExamples, getFullId, getIncorrectExamples, getLocQualityIssueType, getMinPrevMatches, getPriority, getRuleOptions, getSentenceWithImmunization, getSourceFile, getSubId, getTags, getToneTags, getUrl, hasTag, hasToneTag, isDefaultOff, isDefaultTempOff, isDictionaryBasedSpellingRule, isGoalSpecific, isIncludedInHiddenMatches, isOfficeDefaultOff, isOfficeDefaultOn, makeAntiPatterns, setCategory, setCorrectExamples, setDefaultOff, setDefaultOn, setDefaultTempOff, setDistanceTokens, setErrorTriggeringExamples, setExamplePair, setGoalSpecific, setIncludedInHiddenMatches, setIncorrectExamples, setLocQualityIssueType, setMinPrevMatches, setOfficeDefaultOff, setOfficeDefaultOn, setPremium, setPriority, setTags, setToneTags, setUrl, supportsLanguage, toRuleMatchArray, useInOffice
-
Field Details
-
RULE_ID
- See Also:
-
logger
private static final org.slf4j.Logger logger -
models
private static final com.google.common.cache.LoadingCache<RemoteRuleConfig,RemoteLanguageModel> models -
suggestionLimit
protected int suggestionLimit -
model
-
wrappedRule
-
MIN_WORDS
private static final int MIN_WORDS- See Also:
-
MAX_ERROR_RATE
private static final double MAX_ERROR_RATE- See Also:
-
-
Constructor Details
-
BERTSuggestionRanking
public BERTSuggestionRanking(Language language, Rule rule, RemoteRuleConfig config, boolean inputLogging)
-
-
Method Details
-
prepareSuggestions
transform suggestions before resorting, e.g. limit resorting to top-n candidates- Returns:
- transformed suggestions
-
prepareRequest
protected RemoteRule.RemoteRequest prepareRequest(List<AnalyzedSentence> sentences, Long textSessionId) Description copied from class:RemoteRulerun local preprocessing steps (or just store sentences)- Specified by:
prepareRequestin classRemoteRule- Parameters:
sentences- text to processtextSessionId- session ID for caching, partial rollout, A/B testing- Returns:
- parameter for executeRequest/fallbackResults
-
fallbackResults
Description copied from class:RemoteRulefallback if executeRequest times out or throws an error- Specified by:
fallbackResultsin classRemoteRule- Parameters:
request- returned by prepareRequest- Returns:
- local results for this rule
-
executeRequest
protected Callable<RemoteRuleResult> executeRequest(RemoteRule.RemoteRequest request, long timeoutMilliseconds) throws TimeoutException - Specified by:
executeRequestin classRemoteRule- Parameters:
request- returned by prepareRequesttimeoutMilliseconds- timeout for this operation, <=0 -> unlimited- Returns:
- callable that sends request, parses and returns result for this remote rule
- Throws:
TimeoutException- if timeout was exceeded
-
buildRequest
-
getId
Description copied from class:RuleA string used to identify the rule in e.g. configuration files. This string is supposed to be unique and to stay the same in all upcoming versions of LanguageTool. It's supposed to contain only the charactersA-Zand the underscore.- Overrides:
getIdin classRemoteRule
-
getDescription
Description copied from class:RuleA short description of the error this rule can detect, usually in the language of the text that is checked.- Specified by:
getDescriptionin classRule
-