Package: hazm
Hazm - Persian NLP ToolkitEvaluationIntroductionFeaturesInstallationPretrained-ModelsUsageDocumentationHazm in other languagesContributionThanksCode contributoresOthersEvaluationModule nameDependencyParser85.6%POSTagger98.8%Chunker93.4%Lemmatizer89.9%MetricValueSpacyPOSTaggerPrecision0.99250Recall0.99249F1-Score0.99249EZ Detection in SpacyPOSTaggerPrecision0.99301Recall0.99297F1-Score0.99298SpacyChunkerAccuracy96.53%F-Measure95.00%Recall95.17%Precision94.83%SpacyDependencyParserTOK Accuracy99.06UAS92.30LAS89.15SENT Precision98.84SENT Recall99.38SENT F-Measure99.11IntroductionHazmis a python library to perform natural language processing tasks on Persian text. It offers various features for analyzing, processing, and understanding Persian text. You can use Hazm to normalize text, tokenize sentences and words, lemmatize words, assign part-of-speech tags, identify dependency relations, create word and sentence embeddings, or read popular Persian corpora.FeaturesNormalization:Converts text to a standard form, such as removing diacritics, correcting spacing, etc.Tokenization:Splits text into sentences and words.Lemmatization:Reduces words to their base forms.POS tagging:Assigns a part of speech to each word.Dependency parsing:Identifies the syntactic relations between words.Embedding:Creates vector representations of words and sentences.Persian corpora reading:Easily read popular Persian corpora with ready-made scripts and minimal code.InstallationTo install the latest version of Hazm, run the following command in your terminal:pip install hazmAlternatively, you can install the latest update from GitHub (this version may be unstable and buggy):pip install git+https://github.com/roshan-research/hazm.gitPretrained-ModelsFinally if you want to use our pretrained models, you can download it from the links below:Module nameSizeDownload WordEmbedding~ 5 GBDownload SentEmbedding~ 1 GBDownload POSTagger~ 18 MBDownload DependencyParser~ 15 MBDownload Chunker~ 4 MBDownload spacy_pos_tagger_parsbertpostagger~ 630 MBDownload spacy_pos_tagger_parsbertpostagger95~ 630 MBDownload spacy_chunker_uncased_bert~ 650 MBDownload spacy_chunker_parsbert~ 630 MBDownload spacy_dependency_parser~ 630 MBUsage>>>fromhazmimport*>>>normalizer=Normalizer()>>>normalizer.normalize('اصلاح نويسه ها و استفاده از نیم‌فاصله پردازش را آسان مي كند')'اصلاح نویسه‌ها و استفاده از نیم‌فاصله پردازش را آسان می‌کند'>>>sent_tokenize('ما هم برای وصل کردن آمدیم! ولی برای پردازش، جدا بهتر نیست؟')['ما هم برای وصل کردن آمدیم!','ولی برای پردازش، جدا بهتر نیست؟']>>>word_tokenize('ولی برای پردازش، جدا بهتر نیست؟')['ولی','برای','پردازش','،','جدا','بهتر','نیست','؟']>>>stemmer=Stemmer()>>>stemmer.stem('کتاب‌ها')'کتاب'>>>lemmatizer=Lemmatizer()>>>lemmatizer.lemmatize('می‌روم')'رفت#رو'>>>tagger=POSTagger(model='pos_tagger.model')>>>tagger.tag(word_tokenize('ما بسیار کتاب می‌خوانیم'))[('ما','PRO'),('بسیار','ADV'),('کتاب','N'),('می‌خوانیم','V')]>>>spacy_posTagger=SpacyPOSTagger(model_path='MODELPATH')>>>spacy_posTagger.tag(tokens=['من','به','مدرسه','ایران','رفته_بودم','.'])[('من','PRON'),('به','ADP'),('مدرسه','NOUN,EZ'),('ایران','NOUN'),('رفته_بودم','VERB'),('.','PUNCT')]>>>posTagger=POSTagger(model='pos_tagger.model',universal_tag=False)>>>posTagger.tag(tokens=['من','به','مدرسه','ایران','رفته_بودم','.'])[('من','PRON'),('به','ADP'),('مدرسه','NOUN'),('ایران','NOUN'),('رفته_بودم','VERB'),('.','PUNCT')]>>>chunker=Chunker(model='chunker.model')>>>tagged=tagger.tag(word_tokenize('کتاب خواندن را دوست داریم'))>>>tree2brackets(chunker.parse(tagged))'[کتاب خواندن NP] [را POSTP] [دوست داریم VP]'>>>spacy_chunker=SpacyChunker(model_path='model_path')>>>tree=spacy_chunker.parse(sentence=[('نامه','NOUN,EZ'),('ایشان','PRON'),('را','ADP'),('دریافت','NOUN'),('داشتم','VERB'),('.','PUNCT')])>>>print(tree)(S(NPنامه/NOUN,EZایشان/PRON)(POSTPرا/ADP)(VPدریافت/NOUNداشتم/VERB)./PUNCT)>>>word_embedding=WordEmbedding(model_type='fasttext',model_path='word2vec.bin')>>>word_embedding.doesnt_match(['سلام','درود','خداحافظ','پنجره'])'پنجره'>>>word_embedding.doesnt_match(['ساعت','پلنگ','شیر'])'ساعت'>>>parser=DependencyParser(tagger=tagger,lemmatizer=lemmatizer)>>>parser.parse(word_tokenize('زنگ‌ها برای که به صدا درمی‌آید؟'))<DependencyGraphwith8nodes>>>>spacy_parser=SpacyDependencyParser(tagger=tagger,lemmatizer=lemmatizer)>>>spacy_parser.parse_sents([word_tokenize('زنگ‌ها برای که به صدا درمی‌آید؟')])DocumentationVisithttps://roshan-ai.ir/hazm/docsto view the full documentation.Hazm in other languagesDisclaimer:These ports are not developed or maintained by Roshan. They may not have the same functionality or quality as the original Hazm..JHazm: A Java port of HazmNHazm: A C# port of HazmContributionWe welcome and appreciate any contributions to this repo, such as bug reports, feature requests, code improvements, documentation updates, etc. Please follow theContribution guidelinewhen contributing. You can open an issue, fork the repo, write your code, create a pull request and wait for a review and feedback. Thank you for your interest and support in this repo!ThanksCode contributoresOthersThanks toVirastyarproject for providing the persian word list.