Hướng dẫn nlp spelling correction python - trăn sửa chính tả nlp
Trong xử lý ngôn ngữ tự nhiên, điều quan trọng là các lỗi chính tả nên ít nhất có thể để bất cứ điều gì chúng ta thực hiện nên chính xác cao. Có những thư viện thực hiện nhiệm vụ tẻ nhạt này, thay vì bạn thực hiện tất cả các kiểm tra và sửa chữa. Chúng tôi sẽ sử dụng khoảng cách Levenshtein, khoảng cách Hamming, Needman-Scunsch để kiểm tra độ chính xác của đầu ra.levenshtein distance, Hamming distance, Needleman-Wunsch to check accuracy of output. Sử dụng ở đâu và tại sao
Thư viện chúng tôi sẽ sử dụng:
Hãy để sử dụng một số mẫu para và gây ra một số lỗi chính tả Lỗi gây ra đoạn văn:para_1: para_1 = “wherre is the love hehad dated forImuch of the past who couqdn’tread in sixthgrade and ins pired him” para_2: para_2 = """As far as I am abl to judg, after long attnding to the sbject, the condiions of lfe apear to act in two ways—directly on the whle organsaton or on certin parts alne and indirectly by afcting the reproducte sstem. Wit respct to te dirct action, we mst bea in mid tht in every cse, as Profesor Weismann hs latly insistd, and as I have inidently shwn in my wrk on "Variatin undr Domesticcation," thcere arae two factrs: namly, the natre of the orgnism and the natture of the condiions. The frmer sems to be much th mre importannt; foor nealy siimilar variations sometimes aris under, as far as we cn juddge, disimilar conditios; annd, on te oter hannd, disssimilar variatioons arise undder conditions which aappear to be nnearly uniiform. The efffects on tthe offspring arre ieither definnite or in definite. They maay be considdered as definnite whhen allc or neearly all thhe ofefspring off inadividuals exnposed tco ceertain conditionas duriing seveal ggenerations aree moodified in te saame maner.""" para_3: para_3 = """Cinderella came frm a grea family. She is the only daughter of an affluent and widowrr duke who has rewed to provide her witha stepmom and two stepsistrs. Cinderella’s mother died due to illness when she was stilll a younng girl, leawing her with a doll, faworite dress, and a pair of glasss slipppers."""
!wget https://github.com/bakwc/JamSpell-models/raw/master/en.tar.gz
Lưu ý: Bạn có thể phải đối mặt với vấn đề trong việc cài đặt và chạy Jamspell, vì vậy tôi đã tạo một container Docker phơi bày gói Jamspell dưới dạng API, mà bạn có thể chạy trên máy cục bộ của mình. Bạn có thể tìm thấy các hướng dẫn ở đây về cách chạy hình ảnh Docker và đưa ra yêu cầu.: You might face problem in installing and running jamspell, so i have made a docker container that exposes jamspell package as API, that you can run on your local machine. You can find instructions here on how to run docker image and make a request.
Ở đây tôi đã tải freq_dictionay_symspellpy.txt được sử dụng như một kho từ. Dữ liệu ở dạng 2 cột được phân tách bằng không gian, cột 1 là Word, cột thứ 2 là tần số của từ đó. freq_dictionay_symspellpy.txtBạn có thể sử dụng kho văn bản của riêng bạn. Corpus được sử dụng trong mã có thể được tìm thấy ở đây from symspellpy import SymSpell Bây giờ khi chúng tôi đã tải cho các từ chính xác của chúng tôi trong para_2 = """As far as I am abl to judg, after long attnding to the sbject, the condiions of lfe apear to act in two ways—directly on the whle organsaton or on certin parts alne and indirectly by afcting the reproducte sstem. Wit respct to te dirct action, we mst bea in mid tht in every cse, as Profesor Weismann hs latly insistd, and as I have inidently shwn in my wrk on "Variatin undr Domesticcation," thcere arae two factrs: namly, the natre of the orgnism and the natture of the condiions. The frmer sems to be much th mre importannt; foor nealy siimilar variations sometimes aris under, as far as we cn juddge, disimilar conditios; annd, on te oter hannd, disssimilar variatioons arise undder conditions which aappear to be nnearly uniiform. The efffects on tthe offspring arre ieither definnite or in definite. They maay be considdered as definnite whhen allc or neearly all thhe ofefspring off inadividuals exnposed tco ceertain conditionas duriing seveal ggenerations aree moodified in te saame maner.""" 0, hãy thử sửa chính tả các từ chính tả.terms = symsp.lookup_compound(para_1, Đầu ra
from textblob import TextBlobprint(str(TextBlob(para_1).correct()))
Lưu ý: Bạn có thể phải đối mặt với vấn đề trong việc cài đặt và chạy Jamspell, vì vậy tôi đã tạo một container Docker phơi bày gói Jamspell dưới dạng API, mà bạn có thể chạy trên máy cục bộ của mình. Bạn có thể tìm thấy các hướng dẫn ở đây về cách chạy hình ảnh Docker và đưa ra yêu cầu.: yellow are the high score (Higher the better) among symspell, jamspell, textblob against para1, para2, para3 and measuring it with 3 different similarity measures with help of Damerau–Levenshtein, Hamming distance, Needleman-Wunsch. But it is just a rough estimation, you can check string output below. Symspellpy |