Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LatinIME
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
keyboard
LatinIME
Commits
1860a5f5
Commit
1860a5f5
authored
1 month ago
by
Aleksandras Kostarevas
Browse files
Options
Downloads
Patches
Plain Diff
Add logic to mix dictionary space replacement suggestions when using LM
parent
4498d9b0
Branches
model-metadata
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
java/src/org/futo/inputmethod/latin/xlm/LanguageModelFacilitator.kt
+43
-1
43 additions, 1 deletion
...rg/futo/inputmethod/latin/xlm/LanguageModelFacilitator.kt
with
43 additions
and
1 deletion
java/src/org/futo/inputmethod/latin/xlm/LanguageModelFacilitator.kt
+
43
−
1
View file @
1860a5f5
...
...
@@ -39,6 +39,7 @@ import org.futo.inputmethod.latin.uix.getSetting
import
org.futo.inputmethod.latin.uix.getSettingFlow
import
org.futo.inputmethod.latin.utils.AsyncResultHolder
import
org.futo.inputmethod.latin.utils.SuggestionResults
import
kotlin.math.ceil
val
AutocorrectThresholdSetting
=
SettingsKey
(
...
...
@@ -72,6 +73,21 @@ private fun SuggestedWordInfo.add(other: SuggestedWordInfo): SuggestedWordInfo {
return
result
}
private
fun
SuggestedWordInfo
.
scoreAtLeast
(
other
:
SuggestedWordInfo
):
SuggestedWordInfo
{
val
result
=
SuggestedWordInfo
(
mWord
,
mPrevWordsContext
,
mScore
.
coerceAtLeast
(
other
.
mScore
+
1
),
SuggestedWordInfo
.
KIND_WHITELIST
or
SuggestedWordInfo
.
KIND_FLAG_APPROPRIATE_FOR_AUTO_CORRECTION
,
null
,
0
,
0
)
return
result
}
private
fun
levenshteinDistance
(
s1
:
String
,
s2
:
String
):
Int
{
val
len1
=
s1
.
length
val
len2
=
s2
.
length
...
...
@@ -397,7 +413,33 @@ public class LanguageModelFacilitator(
}
}
suggestionResults
.
addAll
(
reweightedSuggestions
.
filter
{
!
filtered
.
contains
(
it
)
})
// Add reweightedSuggestions, with space replacement logic. It can replace one of the LM
// suggestions if the top dictionary result has a space, based on heuristics about the
// relative quality of the LM suggestion
val
spaceReplacementPossible
=
maxWordDict
!=
null
&&
maxWordDict
.
word
.
count
{
it
==
' '
}
==
1
var
spaceReplacementPerformed
=
false
for
(
i
in
0
until
reweightedSuggestions
.
size
)
{
val
word
=
reweightedSuggestions
[
i
]
if
(
filtered
.
contains
(
word
))
continue
if
(!
spaceReplacementPerformed
&&
spaceReplacementPossible
&&
(
// If the dict score is high enough, allow the space suggestion
((
maxWordDict
.
mScore
)
>
(
word
.
mScore
/
3
))
// Most LM-generated dashed suggestions are distractions, so accept the space suggestion
||
(
word
.
word
.
contains
(
'-'
))
// If the typed word is much longer than the transformer word, just accept the space suggestion
||
(
values
.
composedData
.
mTypedWord
.
length
>
ceil
(
word
.
word
.
length
*
3.0
/
2.0
))
)
)
{
val
clone
=
maxWordDict
.
scoreAtLeast
(
word
)
suggestionResults
.
add
(
clone
)
spaceReplacementPerformed
=
true
continue
}
suggestionResults
.
add
(
word
)
}
if
(
suggestionResults
.
mRawSuggestions
!=
null
)
{
suggestionResults
.
mRawSuggestions
.
addAll
(
reweightedSuggestions
.
filter
{
!
filtered
.
contains
(
it
)
})
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment