鱼C论坛

 找回密码
 立即注册
12
返回列表 发新帖
楼主: blackantt

[已解决]fasttext怎么不管用?结果错的太离谱。。。。。。

[复制链接]
发表于 2023-5-13 12:55:11 | 显示全部楼层

多平了又没事,浪费你的限额

评分

参与人数 3荣誉 0 鱼币 +5 贡献 +3 收起 理由
歌者文明清理员 + 2 + 3 不会滴
sfqxx + 5
Threebody1 -2 当然有事

查看全部评分

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-5-13 12:57:04 | 显示全部楼层
@Threebody1 你在扣,等会我大号限额回来了我扣你的!

评分

参与人数 1荣誉 +1 鱼币 +2 收起 理由
Threebody1 + 1 + 2 okok

查看全部评分

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-5-13 13:06:53 | 显示全部楼层
陶远航 发表于 2023-5-13 12:02
那您解决了是否可以给我最佳答案呢

我本来的需求是从多语种的文本中,比如
titeann an oíche
ar an ngliomadóir . . .
is ar na gliomaigh

night falls
on the lobster fsher . . .
and on the lobsters


分离出英语句子。但不能精准实现。 现在干脆判断非纯英语文件,把非纯英语的源文件删掉。只要纯英语的文件做输入。
def has_only_latin_letters(name):           #如果有不是26个字母,数字,英文符号的句子行,则跳过此句
    char_set = string.printable
    return all((True if x in char_set else False for x in name))
if has_only_latin_letters(txt2) == False:
    # continue
    print('non English')
else:
    print('English')
但这种也有问题,万一一个英文文件中混入一个其它语种字母,也就被误伤了。  还得加上 非英语 字母的百分比
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-5-13 13:09:55 | 显示全部楼层
blackantt 发表于 2023-5-13 13:06
我本来的需求是从多语种的文本中,比如
titeann an oíche
ar an ngliomadóir . . .

您可以使用以下方法来检测文件中非拉丁字母的百分比。基于该比例,您可以决定阈值以确定是否将文件标记为非纯英语文件:
import string
from collections import Counter

def non_latin_ratio(text):
    total_chars = len(text)
    char_set = string.ascii_letters + string.digits + string.punctuation + string.whitespace # 添加常见英文字符
    non_latin_chars = [char for char in text if char not in char_set]
    non_latin_count = len(non_latin_chars)
    return (non_latin_count/total_chars) * 100

file_text = """titeann an oíche
ar an ngliomadóir . . .
is ar na gliomaigh

night falls
on the lobster fsher . . .
and on the lobsters"""

# 将换行符替换为空格
cleaned_text = file_text.replace("\n", " ")
ratio = non_latin_ratio(cleaned_text)

# 设定阈值为1%,您可以根据具体需求调整。
threshold = 1

if ratio > threshold:
    print("非纯英语")
else:
    print("纯英语")
此代码示例根据阈值判断输入文本是否为非纯英语。您可以根据具体需求进行调整。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-9-23 07:23

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表