Hướng dẫn remove stop words python - loại bỏ các từ dừng python
Quá trình chuyển đổi dữ liệu thành một cái gì đó mà máy tính có thể hiểu được gọi là xử lý trước. Một trong những hình thức chính của xử lý trước là lọc ra dữ liệu vô dụng. Trong xử lý ngôn ngữ tự nhiên, các từ vô dụng (dữ liệu), được gọi là các từ dừng. & Nbsp; & nbsp;pre-processing. One of the major forms of pre-processing is to filter out useless data. In natural language processing, useless words (data), are referred to as stop words. Những từ dừng là gì? Các từ dừng: Một từ dừng là một từ thường được sử dụng (chẳng hạn như là The The The, một Do kết quả của một truy vấn tìm kiếm. & nbsp; chúng tôi sẽ không muốn những từ này chiếm không gian trong cơ sở dữ liệu của chúng tôi hoặc chiếm thời gian xử lý có giá trị. Đối với điều này, chúng ta có thể loại bỏ chúng một cách dễ dàng, bằng cách lưu trữ một danh sách các từ mà bạn xem xét để ngăn chặn các từ. NLTK (Bộ công cụ ngôn ngữ tự nhiên) trong Python có một danh sách các từ dừng được lưu trữ trong 16 ngôn ngữ khác nhau. Bạn có thể tìm thấy chúng trong thư mục NLTK_DATA. Trang chủ/Pratima/NLTK_DATA/Corpora/Stopwords là địa chỉ thư mục. A stop word is a commonly used word (such as “the”, “a”, “an”, “in”) that a search engine has been programmed to
ignore, both when indexing entries for searching and when retrieving them as the result of a search query. Để kiểm tra danh sách các từ dừng, bạn có thể nhập các lệnh sau vào vỏ Python. & NBSP; & nbsp; import nltk from nltk.corpus import stopwords print(stopwords.words('english')) s Có ',' với ',' họ ',' riêng ',' an ',' be ',' some ',' for ',' do ',' its ',' yours ',' như ',' thành 'thành' , 'của', 'hầu hết', 'chính nó', 'khác', 'off', 'là', 's', 'am', 'hoặc', 'who', 'as', 'from', '' anh ấy ',' mỗi ',' ',' chính họ ',' cho đến ',' bên dưới ',' là ',' chúng tôi ',' những 'này', 'của bạn', 'của anh ấy', 'qua', 'don' , 'cũng không', 'tôi', 'là', 'cô ấy', 'hơn', 'chính anh ấy', 'cái này', 'xuống', 'nên', 'của chúng tôi', 'của họ', 'trong khi', ' Ở trên ',' cả ',' lên ',' thành ',' của chúng tôi ',' đã ',' cô ấy ',' tất cả ',' không ',' khi ',' tại ',' bất kỳ ',' trước 'trước' , 'họ', 'giống nhau', 'và', 'đã', 'có', 'trong', 'will', 'on', 'không', 'chính mình', 'sau đó', 'đó', ',' bởi vì ',' cái gì ',' trên ',' tại sao ',' vì vậy ',' có thể ',' đã làm ',' không ',' bây giờ ',' dưới ',' anh ',' bạn ',' cô ấy ' , 'có', 'công bằng', 'ở đâu', 'quá', 'chỉ', 'bản thân mình', 'mà', 'những người', 'i', 'sau', 'vài', 'ai', '' T ',' là ',' nếu ',' của họ ',' của tôi ',' chống lại ',' a ',' bởi ',' làm ',' nó ',' làm thế nào ',' hơn nữa ',' là 'là' , 'đây', 'tha Nát} & nbsp; Lưu ý: Bạn thậm chí có thể sửa đổi danh sách bằng cách thêm các từ bạn chọn vào tiếng Anh .txt. tệp trong thư mục stopwords. & nbsp; & nbsp; Xóa các từ dừng bằng NLTK Chương trình sau đây loại bỏ các từ dừng khỏi một đoạn văn bản: & nbsp; & nbsp; Python3
['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']0 ['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']1 ['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']2 ['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']1 ['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']4 ['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']5 ['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']6 ['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']7 ['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']8 ['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']1 from 0
['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']1 from 3from 4 from 5from 6 ['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']8__
['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']1 nltk.corpus 5
Output: ['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.'] Thực hiện các hoạt động stopwords trong một tệp Trong mã bên dưới, Text.txt là tệp đầu vào gốc trong đó các từ dừng sẽ được xóa. FilteredText.txt là tệp đầu ra. Nó có thể được thực hiện bằng cách sử dụng mã sau: & nbsp; & nbsp; Python3
['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']2 ['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']1 ['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']4 ['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']5 ['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']6 from 7
['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']1 nltk.tokenize 0nltk.tokenize 1nltk.tokenize 2__
['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']1 nltk.tokenize 6
['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']1 nltk.tokenize 9
Các
['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']00 ['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']01 ['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']02 ['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']03
['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']05 Đây là cách chúng tôi làm cho nội dung được xử lý của chúng tôi hiệu quả hơn bằng cách loại bỏ các từ không đóng góp cho bất kỳ hoạt động nào trong tương lai. Bài viết này được đóng góp bởi Pratima Upadhyay. Nếu bạn thích GeekSforGeeks và muốn đóng góp, bạn cũng có thể viết một bài viết bằng Write.GeekSforGeek.org hoặc gửi bài viết của bạn. Xem bài viết của bạn xuất hiện trên trang chính của GeekSforGeek và giúp các chuyên viên máy tính khác. Xin vui lòng viết nhận xét nếu bạn tìm thấy bất cứ điều gì không chính xác hoặc bạn muốn chia sẻ thêm thông tin về chủ đề được thảo luận ở trên. & NBSP; |