Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

วิธีเตรียมชุดข้อมูล StackOverflow Questions ด้วย TensorFlow ใน Python

บทนำ

TextVectorization layer จัดการ Standardization (ลบ punctuation, HTML), Tokenization (แยกคำ), Vectorization (แปลงเป็นตัวเลข)

การติดตั้ง

pip install tensorflow

ตัวอย่างโค้ด

VOCAB_SIZE = 10000
binary_vectorize_layer = TextVectorization(
    max_tokens=VOCAB_SIZE,
    output_mode='binary'
)
MAX_SEQUENCE_LENGTH = 250
int_vectorize_layer = TextVectorization(
    max_tokens=VOCAB_SIZE,
    output_mode='int',
    output_sequence_length=MAX_SEQUENCE_LENGTH
)

ผลลัพธ์

The preprocessing of text begins

คำอธิบาย

  • Binary layer: สำหรับ Bag-of-words model

  • Int layer: สำหรับ Sequence model (RNN/Transformer) ระบุ sequence length

  • Standardization: ลบ punctuation, HTML tags

  • Tokenization: แยกคำด้วย whitespace