0Pricing
NLP Academy · บทเรียน

ตัดเครื่องหมายวรรคตอนและสัญลักษณ์

ทำความสะอาดอักขระที่ทำให้โมเดลสับสน

ตัดเครื่องหมายวรรคตอนและสัญลักษณ์ เป็นบทเรียน NLP Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน NLP Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส NLP Academy มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Punctuation Is Noise Too

After stopwords, the next clutter is symbols. Commas, dollar signs, and emoji can confuse a model, so we often strip punctuation away.

Why It Matters

Without cleanup, your model sees cat, and cat as two different tokens. That trailing comma splits one word into two features.

Python Knows the Marks

The string module hands you every common mark in one constant called punctuation, so you never type them out by hand.

import string
print(string.punctuation)

The translate Trick

The fastest way to delete characters is str.translate with a table that maps each mark to nothing at all.

table = str.maketrans("", "", string.punctuation)
clean = "hello, world!".translate(table)
print(clean)

Per-Token Cleaning

You can also strip marks token by token. Apply translate inside a comprehension, then drop any token that became empty.

clean = [t.translate(table) for t in tokens]
clean = [t for t in clean if t]

Regex for Symbols

Need more control than the fixed list? A regex can wipe anything that is not a letter, number, or space.

import re
clean = re.sub(r"[^a-zA-Z0-9 ]", "", text)

Beware of Useful Marks

Some symbols carry meaning. Stripping every dot turns u.s.a into usa, and that may not be what you want for your task.

Numbers Are a Choice

Digits are not punctuation, but they are often noise. Decide on purpose whether to keep or drop numbers for your data.

no_digits = re.sub(r"\d+", "", text)

Watch Unicode Symbols

The ASCII punctuation set misses curly quotes and emoji. A Unicode-aware regex catches the symbols a fixed list leaves behind.

clean = re.sub(r"[^\w\s]", "", text)

Collapse Extra Spaces

Removing marks can leave gaps and double spaces. A quick whitespace squeeze tidies the result back into clean words.

clean = re.sub(r"\s+", " ", clean).strip()

Order of Operations

Sequence matters. Strip punctuation before you split or compare, so trailing marks never sneak into your final tokens.

Quick Check

Pick the cleanest way to delete punctuation from a string.

Recap

You can now strip punctuation with translate or regex, handle Unicode and numbers on purpose, and squeeze leftover spaces for clean tokens.

คำถามที่พบบ่อย

บทเรียน “ตัดเครื่องหมายวรรคตอนและสัญลักษณ์” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “ตัดเครื่องหมายวรรคตอนและสัญลักษณ์” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส NLP Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส NLP Academy มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “ตัดเครื่องหมายวรรคตอนและสัญลักษณ์”

ทำความสะอาดอักขระที่ทำให้โมเดลสับสน คุณปฏิบัติ NLP Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน NLP Academy หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน NLP Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน

บทเรียน “ตัดเครื่องหมายวรรคตอนและสัญลักษณ์” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน NLP Academy นี้ได้ไหม

ได้ บทเรียน NLP Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. Stopword คืออะไร
  2. กรอง Stopword ด้วย NLTK
  3. ตัดเครื่องหมายวรรคตอนและสัญลักษณ์
  4. สร้างฟังก์ชันทำความสะอาดข้อความที่นำกลับมาใช้ใหม่ได้
← กลับไปที่ NLP Academy