确定句子是英语的概率的相对简单方法是什么?

编程入门 行业动态 更新时间:2024-10-25 00:28:56
本文介绍了确定句子是英语的概率的相对简单方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有许多代表不同语言的句子的字符串(字符集合),说:

I have a number of strings (collections of characters) that represent sentences in different languages, say:

你好,我叫乔治.

Hello, my name is George.

Das brot ist肠道.

Das brot ist gut.

...等等

我想给它们中的每一个分配分数(从0 .. 1开始),以表明它们是英语句子的可能性.是否有可以从中执行此操作的算法(或Python库)?

I want to assign each of them scores (from 0 .. 1) indicating the likelihood that they are English sentences. Is there an accepted algorithm (or Python library) from which to do this?

注意:我不在乎英语句子的语法是否完美.

Note: I don't care if the grammar of the English sentence is perfect.

推荐答案

贝叶斯分类器会是完成此任务的好选择:

A bayesian classifier would be a good choice for this task:

>>> from reverend.thomas import Bayes >>> g = Bayes() # guesser >>> g.train('french','La souris est rentrée dans son trou.') >>> g.train('english','my tailor is rich.') >>> g.train('french','Je ne sais pas si je viendrai demain.') >>> g.train('english','I do not plan to update my website soon.') >>> print g.guess('Jumping out of cliffs it not a good idea.') [('english', 0.99990000000000001), ('french', 9.9999999999988987e-005)] >>> print g.guess('Demain il fera très probablement chaud.') [('french', 0.99990000000000001), ('english', 9.9999999999988987e-005)]

更多推荐

确定句子是英语的概率的相对简单方法是什么?

本文发布于:2023-11-28 20:47:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1643896.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:英语   概率   句子   简单   方法

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!