未提供项目说明

BnVec的Python项目详细描述


孟加拉文特征提取程序(BnVec)

BnVec是一个基于孟加拉语自然语言处理的特征抽取器。在

特征提取

  1. CountVectorizer
  2. HashVectorizer
  3. TfIdf
  4. Word Embedding
  5. n-gram

安装

pip install BnVec

示例

1。计数矢量器

  • 拟合n变换
  • 转换
  • 获取单词集

Fit n转换

^{pr2}$

输出:

the countVectorized matrix form of given features

Transform

fromBnVecimportCountVectorizerct=CountVectorizer()get_mat=ct.transform("রাহাত")

输出:

the countVectorized matrix form of given word

Get Wordset

fromBnVecimportCountVectorizerct=CountVectorizer()ct.get_wordSet()

输出:

get the raw wordset used in training model

2。HashVectorizer

  • 拟合n变换
  • 转换
fromBnVecimportHashVectorizercorpus=['আমাদের দেশ বাংলাদেশ','আমার বাংলা']Vectorizer=HashVectorizer()n_features=8X=Vectorizer.fit_transform(corpus,n_features)corpus_t=["আমাদের দেশ অনেক সুন্দর"]Xf=Vectorizer.transform(corpus_t)print(X.shape,Xf.shape)print("=====================================")print(X)print("=====================================")print(Xf)

输出:

(2, 8) (1, 8)
=====================================
  (0, 7)	-1.0
  (1, 7)	-1.0
=====================================
  (0, 0)	0.5773502691896258
  (0, 2)	0.5773502691896258
  (0, 7)	-0.5773502691896258

Get Wordset

3。TfIdf

  • 拟合n变换
  • 转换
  • 系数

Fit n转换

fromBnVecimportTfIdfVectorizerk=TfIdfVectorizer()doc=["কাওছার আহমেদ","শুভ হাইদার"]matrix1=k.fit_transform(doc)print(matrix1)

输出:

[[0.150515 0.150515 0.       0.      ]
 [0.       0.       0.150515 0.150515]]

Transform

fromBnVecimportTfIdfVectorizerk=TfIdfVectorizer()doc=["আহমেদ সুমন","কাওছার করিম"]matrix2=k.transform(doc)print(matrix2)

输出:

[[0.150515 0.       0.       0.      ]
 [0.       0.150515 0.       0.      ]]

系数

fromBnVecimportTfIdfVectorizerk=TfIdfVectorizer()doc=["কাওছার আহমেদ","শুভ হাইদার"]k.fit_transform(doc)wordset,idf=k.coefficients()print(wordset)#Output: ['আহমেদ', 'কাওছার', 'হাইদার', 'শুভ']print(idf)'''Output: {'আহমেদ': 0.3010299956639812, 'কাওছার': 0.3010299956639812, 'হাইদার': 0.3010299956639812, 'শুভ': 0.3010299956639812}'''

4。单词嵌入

  • Word2Vec

    • 培训
    • 获取词向量
    • 获取相似性
    • 得到n个相似的单词
    • 获取中间词
    • 得到奇怪的词
    • 求相似图

Training

fromBnVecimportBN_Word2Vec#Training Against Sentencesw2v=BN_Word2Vec(sentences=[['আমার','প্রিয়','জন্মভূমি'],['বাংলা','আমার','মাতৃভাষা'],['আমার','প্রিয়','জন্মভূমি'],['বাংলা','আমার','মাতৃভাষা'],['আমার','প্রিয়','জন্মভূমি'],['বাংলা','আমার','মাতৃভাষা']])w2v.train()#Training Against one Text Corpusw2v=BN_Word2Vec(corpus_file="path_to_corpus.txt")w2v.train()#Training Against Multiple corpuses'''    path      ->corpus        ->1.txt        ->2.txt        ->3.txt'''w2v=BN_Word2Vec(corpus_path="path/corpus")w2v.train(epochs=25)#Training Against a Dataframe Columnw2v=BN_Word2Vec(df=news_data['text_content'])w2v.train(epochs=25)

训练完成后,模型“w2v_模型”及其支持向量文件将被保存到当前目录。在

如果使用任何预先训练的模型,请在初始化BN\u Word2Vec()时指定它。否则不需要型号名称。

Get Word Vector

fromBnVecimportBN_Word2Vecw2v=BN_Word2Vec(model_name='give the model name here')w2v.get_wordVector('আমার')

获取相似性

fromBnVecimportBN_Word2Vecw2v=BN_Word2Vec(model_name='give the model name here')w2v.get_similarity('ঢাকা','রাজধানী')

输出:

67.457879

Get n个相似单词

fromBnVecimportBN_Word2Vecw2v=BN_Word2Vec(model_name='give the model name here')w2v.get_n_similarWord(['পদ্মা'],n=10)

输出:

[('সেতুর', 0.5857524275779724),
 ('মুলফৎগঞ্জ', 0.5773632526397705),
 ('মহানন্দা', 0.5634652376174927),
 ("'পদ্মা", 0.5617109537124634),
 ('গোমতী', 0.5605217218399048),
 ('পদ্মার', 0.5547558069229126),
 ('তুলসীগঙ্গা', 0.5274507999420166),
 ('নদীর', 0.5232067704200745),
 ('সেতু', 0.5225246548652649),
 ('সেতুতে', 0.5192927718162537)]

Get中间词

得到中心词给定词表的概率分布。在

^{pr21}$

输出:

[("হয়েছে।',", 0.05880642), ('শ্রমিকের', 0.05639163)]

Get奇数单词

从给定单词列表中找出最不匹配的单词

fromBnVecimportBN_Word2Vecw2v=BN_Word2Vec(model_name='give the model name here')w2v.get_oddWords(['চাল','ডাল','চিনি','আকাশ'])

输出:

'আকাশ' 

获取相似性图

创建具有概率的相似单词的条形图

fromBnVecimportBN_Word2Vecw2v=BN_Word2Vec(model_name='give the model name here')w2v.get_similarity_plot('চাউল',5)
  • 快速文本

    • 培训
    • 获取词向量
    • 获取相似性
    • 得到n个相似的单词
    • 获取中间词
    • 得到奇怪的词

Training

fromBnVecimportBN_FastText#Training Against Sentencesft=ft=BN_FastText(sentences=[['আমার','প্রিয়','জন্মভূমি'],['বাংলা','আমার','মাতৃভাষা'],['বাংলা','আমার','মাতৃভাষা'],['বাংলা','আমার','মাতৃভাষা'],['বাংলা','আমার','মাতৃভাষা']])ft.train()#Training Against one Text Corpusft=BN_FastText(corpus_file="path to data or txt file")ft.train()#Training Against Multiple Corpuses'''    path      ->Corpus        ->1.txt        ->2.txt        ->3.txt'''ft=BN_FastText(corpus_path="path/Corpus")ft.train(epochs=25)#Training Against a Dataframe Columnft=BN_FastText(df=news_data['text_content'])ft.train(epochs=25)

训练完成后,模型“ft_model”及其支持向量文件将被保存到当前目录。在

如果不想训练而是使用预训练的模型,请在初始化BN\u FastText()时指定它。否则不需要型号名称。

Get Word Vector

fromBnVecimportBN_FastTextft=BN_FastText(model_name='give the model name here')ft.get_wordVector('আমার')

获取相似性

fromBnVecimportBN_FastTextft=BN_FastText(model_name='give the model name here')ft.get_similarity('ঢাকা','রাজধানী')

输出:

70.56821120

Get n个相似单词

fromBnVecimportBN_FastTextft=BN_FastText(model_name='give the model name here')ft.get_n_similarWord(['পদ্মা'],n=10)

输出:

^{pr31}$

Get奇数单词

从给定单词列表中找出最不匹配的单词

fromBnVecimportBN_FastTextft=BN_FastText(model_name='give the model name here')ft.get_oddWords(['চাল','ডাল','চিনি','আকাশ'])

输出:

'আকাশ' 

获取相似性图

创建具有概率的相似单词的条形图

fromBnVecimportBN_FastTextft=BN_FastText(model_name='give the model name here')ft.get_similarity_plot('চাউল',5)
  • 手套

    • 培训
    • 得到n个相似的单词

Training

^{pr35}$

训练完成后,模型“手套模型”及其支持向量文件将被保存到当前目录。在

如果不想训练而是使用预训练的模型,请在初始化BN\u FastText()时指定它。否则不需要型号名称。

Get n个相似单词

fromBnVecimportBN_GloVeglv=BN_GloVe(model_name='give the model name here')glv.get_n_similarWord(['পদ্মা'],n=10)

输出:

^{pr31}$

5。nGram

示例

fromBnVecimportgramd=gram()d.n_gram(x,n)

输出:

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何修复尝试将用户签名到服务器主机时出现的“字符串无法转换为json对象”错误?   控制台Java:不使用新行更新命令行中的文本   java servlet接收xml数据时,出现错误   使用REST API在Bitbucket中复制或复制存储库   java如何在JavaFX中对齐一行?   java如何在活动中显示通过服务获得的数据?   返回BigDecimal作为字符串:返回int   java组织。openqa。硒。InvalidSelectorException:尝试查找元素时选择器无效   java仅在阻塞状态下通知和通知所有影响线程   java JBOSS无法启动部署   java方法的返回值能保证类型安全吗?   JavaeShadoop序列化组织。阿帕奇。hadoop。木卫一。短写失败   java如果我在同一个类上同步了两个方法,它们能同时运行吗?   不使用java数据库的spring分页实现   java如何将字符串切碎成这样的数组?