อธิบาย Bigrams และ Trigrams
เลื่อนหน้าต่างไปบนโทเคน
อธิบาย Bigrams และ Trigrams เป็นบทเรียน NLP Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน NLP Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส NLP Academy มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
Naming the N-Grams
The n in n-gram is just a number. Pick n and you decide how many neighboring words each feature bundles together.
Meet the Bigram
A bigram is an n-gram of size two, every adjacent pair of words. It is the most common upgrade over plain single words. 👍
Bigrams in Action
From four words you get three overlapping pairs. Notice how each bigram shares one word with the next one.
words = "i love clean code".split()
bigrams = list(zip(words, words[1:]))
print(bigrams)Meet the Trigram
A trigram takes three words at a time. It captures even more context, like is not good as one unit.
words = "this is not good".split()
trigrams = list(zip(words, words[1:], words[2:]))
print(trigrams)How Many Do You Get?
For a sentence of N words, you get N minus n plus one n-grams. So 4 words give 3 bigrams and 2 trigrams.
The Window Slides
Each n-gram comes from a small window moving one word forward. Overlap is the point, since shared words stitch context together.
A Reusable Helper
You can build any n-gram with one tidy function using zip. Change the value of n and the same code handles bigrams or trigrams.
def ngrams(words, n):
return list(zip(*[words[i:] for i in range(n)]))Bigger N, More Context
Higher values of n hold longer phrases, so they capture context more precisely. That power comes with a cost you will meet soon.
Bigger N, Rarer Grams
The longer the run, the less often that exact sequence repeats. Large n-grams become rare, appearing in few documents.
Why Bigrams Are Popular
Bigrams hit a sweet spot: enough context to catch not bad, common enough to repeat across texts. That balance makes them a reliable default.
Mixing Sizes
You rarely use one size alone. Most pipelines combine unigrams and bigrams so the model sees both single words and their key pairs.
Quick Check
How many bigrams come from the sentence text is just data, which has four words?
Recap: Bigrams and Trigrams
A bigram joins two words, a trigram joins three. Bigger n holds more context but appears less often. Next you will let scikit-learn build them. ⚙️
คำถามที่พบบ่อย
บทเรียน “อธิบาย Bigrams และ Trigrams” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “อธิบาย Bigrams และ Trigrams” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส NLP Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส NLP Academy มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “อธิบาย Bigrams และ Trigrams”
เลื่อนหน้าต่างไปบนโทเคน คุณปฏิบัติ NLP Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน NLP Academy หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน NLP Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน
บทเรียน “อธิบาย Bigrams และ Trigrams” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน NLP Academy นี้ได้ไหม
ได้ บทเรียน NLP Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- เหตุใดคำเดี่ยวจึงสูญเสียความหมาย
- อธิบาย Bigrams และ Trigrams
- คุณลักษณะ N-Gram ใน scikit-learn
- เลือกช่วง N-Gram ที่เหมาะสม