Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model 1 expansion: translating to the null word #1

Open
bennokr opened this issue Apr 10, 2014 · 0 comments
Open

Model 1 expansion: translating to the null word #1

bennokr opened this issue Apr 10, 2014 · 0 comments

Comments

@bennokr
Copy link
Collaborator

bennokr commented Apr 10, 2014

This code looks for the words that probably make a sentence shorter, so you can delete them when translating:

c = Counter()
for s,t in corpus():
    sc = (len(s)-len(t)) / float(len(s))
    shorten = Counter(s)
    for w in shorten:
        c[w] += shorten[w] * sc
c.most_common()

The first three look good:

('te', 4.471595928036059),
(''', 4.035303262272552),
('s', 3.6778059597504105),

but the rest is not really.

What you'd actually want to do is look for bigrams that get translated into one word, and choose the one both words point to. Or, when translating, merge doubles:

Tot slot, blah blah -> Finally finally, blah blah -> Finally, blah blah

Another option is to add null words to the sentence pairs to make 'em longer:

def lengthen(pairs):
    for i in xrange(len(pairs)):
        fs,es = pairs[i]
        diff = len(fs) - len(es)
        if diff > 0:
            pairs[i] = (fs, es+['NULL']*diff)
        if diff < 0:
            pairs[i] = (fs+['NULL']*abs(diff), es)
        fs,es = pairs[i]
    return pairs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant