1/29
Looks like no tags are added yet.
Cách tải tài nguyên NLTK thường dùng (punkt, stopwords, pos_tag, wordnet, vader_lexicon)?
import nltk; nltk.download('punkt'); nltk.download('stopwords'); nltk.download('averaged_perceptron_tagger'); nltk.download('wordnet'); nltk.download('vader_lexicon')
Cách gửi HTTP request và bóc tách HTML thô bằng requests và BeautifulSoup?
import requests; from bs4 import BeautifulSoup; res = requests.get(url, headers={'User-Agent': 'Mozilla/5.0'}); soup = BeautifulSoup(res.text, 'html.parser')
Cách lấy văn bản thuần túy (loại bỏ thẻ HTML) từ BeautifulSoup?
raw_text = soup.get_text()
Cách xóa các thẻ nhiễu (table, script, style, figure) trong BeautifulSoup trước khi lấy text?
for tag in soup.select('table, script, style, figure'): tag.decompose()
Cách tách câu (Sentence Segmentation) tiếng Anh bằng NLTK?
import nltk; sentences = nltk.sent_tokenize(raw_text)
Cách tách từ (Tokenization) tiếng Anh bằng NLTK?
import nltk; tokens = nltk.word_tokenize(text)
Cách làm sạch token: lowercase, loại bỏ stopwords tiếng Anh, dấu câu và ký tự đặc biệt?
from nltk.corpus import stopwords; import string; stop_words = set(stopwords.words('english')); cleaned = [w.lower() for w in tokens if w.lower() not in stop_words and w not in string.punctuation and w.isalnum()]
Cú pháp RegEx tìm từ duy nhất kết thúc bằng đuôi "-able"?
pattern_able = [w for w in vocab if re.search(r'able$', w, re.IGNORECASE)]
Cú pháp RegEx tìm từ chứa cụm "-ation-" ở giữa từ (có ký tự đứng trước và đứng sau)?
pattern_ation = [w for w in vocab if re.search(r'.+ation.+', w, re.IGNORECASE)]
Cú pháp RegEx tìm từ bắt đầu bằng chữ 'T' hoặc 't' và kết thúc bằng đuôi "-ing"?
pattern_ting = [w for w in vocab if re.search(r'\b[Tt]\w*ing\b', w)]
Cách dùng PorterStemmer trong NLTK để tìm gốc từ (stem)?
from nltk import PorterStemmer; porter = PorterStemmer(); stem = porter.stem(word)
Công thức và code tính Độ đa dạng từ vựng (Lexical Diversity)?
lexical_diversity = len(set(cleaned_tokens)) / len(cleaned_tokens)
Cách tạo danh sách Bigrams và Trigrams từ tập token trong NLTK?
from nltk import bigrams, trigrams; bg = list(bigrams(tokens)); tg = list(trigrams(tokens))
Cách thống kê Top 10 Bigram xuất hiện nhiều nhất bằng FreqDist trong NLTK?
from nltk import FreqDist; fdist = FreqDist(bigrams_list); top10 = fdist.most_common(10)
Cách tra cứu tất cả Synsets của một từ trong WordNet (NLTK)?
from nltk.corpus import wordnet as wn; synsets = wn.synsets('car')
Cách lấy định nghĩa, từ đồng nghĩa (lemmas), hypernyms và hyponyms từ Synset trong WordNet?
syn = wn.synset('car.n.01'); def_text = syn.definition(); lemmas = [l.name() for l in syn.lemmas()]; hyper = syn.hypernyms(); hypo = syn.hyponyms()
Cách tính độ tương đồng ngữ nghĩa (Path Similarity) giữa 2 Synset trong WordNet?
sim = syn1.path_similarity(syn2)
Cách thực hiện POS Tagging cho danh sách token tiếng Anh trong NLTK?
import nltk; pos_tags = nltk.pos_tag(tokenized_sentence)
Cách định nghĩa luật RegEx gom cụm danh từ (NP Chunking) trong NLTK?
grammar = r"NP: {?
Cách chuyển cây cú pháp Chunking (Tree) sang định dạng chuỗi IOB (CoNLL format)?
import nltk; iob_str = nltk.chunk.tree2conllstr(tree)
Cách đánh dấu từ phủ định (mark_negation) trong câu bằng NLTK?
from nltk.sentiment.util import mark_negation; negated_tokens = mark_negation("I don't like it".split())
Cách tính điểm cảm xúc Polarity Scores (pos, neg, neu, compound) bằng VADER NLTK?
from nltk.sentiment.vader import SentimentIntensityAnalyzer; sid = SentimentIntensityAnalyzer(); scores = sid.polarity_scores(text)
Cách trích xuất đặc trưng dạng Binarized (Boolean) cho mô hình Naive Bayes?
def extract_features(doc): words = set(doc.split()); return {f'contains({w})': (w in words) for w in all_words}
Cách huấn luyện và dự đoán xác suất nhãn bằng NaiveBayesClassifier trong NLTK?
classifier = nltk.NaiveBayesClassifier.train(train_set); pred = classifier.classify(test_feat); prob = classifier.prob_classify(test_feat)
Cách trích xuất bộ ba quan hệ (Subject, Relation, Object) bằng RegEx Groups?
pattern = r'([A-Z]\w+)\s+(is located in)\s+([A-Z]\w+)'; matches = re.findall(pattern, text)
Cách tách câu và tách từ ghép tiếng Việt bằng underthesea?
from underthesea import sent_tokenize, word_tokenize; sents = sent_tokenize(text); tokens = word_tokenize(text)
Cách gán nhãn POS và phân tích cú pháp phụ thuộc tiếng Việt bằng underthesea?
from underthesea import pos_tag, dependency_parse; tags = pos_tag(text); dep_tree = dependency_parse(text)
Cách tách từ ghép và POS Tagging tiếng Việt bằng PyVi?
from pyvi import ViTokenizer, ViPosTagger; tokens = ViTokenizer.tokenize(text); words, tags = ViPosTagger.postag(tokens)
Cách chuẩn hóa và xuất dữ liệu danh sách câu sang file JSON chuẩn Label Studio?
import json; data = [{"data": {"text": s}} for s in sentences if len(s) >= 10]; json.dump(data, open('data.json', 'w', encoding='utf-8'), ensure_ascii=False, indent=2)
Định nghĩa thuật toán Minimum Edit Distance (Damerau-Levenshtein)?
Số lượng phép toán tối thiểu (Chèn, Xóa, Thay thế, Đổi chỗ 2 ký tự liền kề) để biến đổi chuỗi này thành chuỗi khác.