Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

translated chapter 0 #70

Merged
merged 6 commits into from
Apr 1, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
173 changes: 173 additions & 0 deletions chapters/th/_toctree.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
- title: 0. ติดตั้งโปรแกรม
sections:
- local: chapter0/1
title: บทนำ

- title: 1. Transformer models
sections:
- local: chapter1/1
title: Introduction
- local: chapter1/2
peeraponw marked this conversation as resolved.
Show resolved Hide resolved
title: Natural Language Processing
- local: chapter1/3
title: Transformers, what can they do?
- local: chapter1/4
title: How do Transformers work?
- local: chapter1/5
title: Encoder models
- local: chapter1/6
title: Decoder models
- local: chapter1/7
title: Sequence-to-sequence models
- local: chapter1/8
title: Bias and limitations
- local: chapter1/9
title: Summary
- local: chapter1/10
title: End-of-chapter quiz
quiz: 1

- title: 2. Using 🤗 Transformers
sections:
- local: chapter2/1
title: Introduction
- local: chapter2/2
title: Behind the pipeline
- local: chapter2/3
title: Models
- local: chapter2/4
title: Tokenizers
- local: chapter2/5
title: Handling multiple sequences
- local: chapter2/6
title: Putting it all together
- local: chapter2/7
title: Basic usage completed!
- local: chapter2/8
title: End-of-chapter quiz
quiz: 2

- title: 3. Fine-tuning a pretrained model
sections:
- local: chapter3/1
title: Introduction
- local: chapter3/2
title: Processing the data
- local: chapter3/3
title: Fine-tuning a model with the Trainer API or Keras
local_fw: { pt: chapter3/3, tf: chapter3/3_tf }
- local: chapter3/4
title: A full training
- local: chapter3/5
title: Fine-tuning, Check!
- local: chapter3/6
title: End-of-chapter quiz
quiz: 3

- title: 4. Sharing models and tokenizers
sections:
- local: chapter4/1
title: The Hugging Face Hub
- local: chapter4/2
title: Using pretrained models
- local: chapter4/3
title: Sharing pretrained models
- local: chapter4/4
title: Building a model card
- local: chapter4/5
title: Part 1 completed!
- local: chapter4/6
title: End-of-chapter quiz
quiz: 4

- title: 5. The 🤗 Datasets library
sections:
- local: chapter5/1
title: Introduction
- local: chapter5/2
title: What if my dataset isn't on the Hub?
- local: chapter5/3
title: Time to slice and dice
- local: chapter5/4
title: Big data? 🤗 Datasets to the rescue!
- local: chapter5/5
title: Creating your own dataset
- local: chapter5/6
title: Semantic search with FAISS
- local: chapter5/7
title: 🤗 Datasets, check!
- local: chapter5/8
title: End-of-chapter quiz
quiz: 5

- title: 6. The 🤗 Tokenizers library
sections:
- local: chapter6/1
title: Introduction
- local: chapter6/2
title: Training a new tokenizer from an old one
- local: chapter6/3
title: Fast tokenizers' special powers
- local: chapter6/3b
title: Fast tokenizers in the QA pipeline
- local: chapter6/4
title: Normalization and pre-tokenization
- local: chapter6/5
title: Byte-Pair Encoding tokenization
- local: chapter6/6
title: WordPiece tokenization
- local: chapter6/7
title: Unigram tokenization
- local: chapter6/8
title: Building a tokenizer, block by block
- local: chapter6/9
title: Tokenizers, check!
- local: chapter6/10
title: End-of-chapter quiz
quiz: 6

- title: 7. Main NLP tasks
sections:
- local: chapter7/1
title: Introduction
- local: chapter7/2
title: Token classification
- local: chapter7/3
title: Fine-tuning a masked language model
- local: chapter7/4
title: Translation
- local: chapter7/5
title: Summarization
- local: chapter7/6
title: Training a causal language model from scratch
- local: chapter7/7
title: Question answering
- local: chapter7/8
title: Mastering NLP
- local: chapter7/9
title: End-of-chapter quiz
quiz: 7

- title: 8. How to ask for help
sections:
- local: chapter8/1
title: Introduction
- local: chapter8/2
title: What to do when you get an error
- local: chapter8/3
title: Asking for help on the forums
- local: chapter8/4
title: Debugging the training pipeline
local_fw: { pt: chapter8/4, tf: chapter8/4_tf }
- local: chapter8/5
title: How to write a good issue
- local: chapter8/6
title: Part 2 completed!
- local: chapter8/7
title: End-of-chapter quiz
quiz: 8

- title: Hugging Face Course Event
sections:
- local: event/1
title: Part 2 Release Event
112 changes: 112 additions & 0 deletions chapters/th/chapter0/1.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# บทนำ

ยินดีต้อนรับเข้าสู่คอร์ส Hugging Face! ในส่วนเริ่มต้นนี้จะพาคุณติดตั้งโปรแกรมหรือสิ่งแวดล้อมในการทำงาน(หรือเรียกว่า working environment) หากคุณเพิ่งเริ่มคอร์สนี้ เราแนะนำให้คุณไปดู [บทที่ 1](/course/chapter1) ก่อน จากนั้นค่อยกลับมาติดตั้ง environtment เพื่อทดลองโค้ดด้วยตัวเอง

คลังชุดคำสั่ง (หรือเรียกว่า library) ต่าง ๆ ที่ใช้ในคอร์สนี้สามารถใช้เป็นชุดคำสั่งสำเร็จในภาษา Python (หรือเรียกว่า Python package) ได้ทั้งหมด ดังนั้น ในส่วนนี้เราจะแสดงวิธีการติดตั้ง Python environment และลง library ที่จำเป็นทั้งหมด

ในส่วนนี้เราจะแสดงวิธีการติดตั้ง working environment อยู่ทั้งหมดสองวิธี ได้แก่ การใช้ Colab notebook และ การใช้สิ่งแวดล้อมจำลองใน Python (หรือเรียกว่า Python virtual environment) คุณสามารถใช้วิธีใดก็ได้ที่ถนัด สำหรับผู้เริ่มต้นแล้ว เราแนะนำให้ใช้ Colab notebook

อย่างไรก็ตาม ในที่นี้จะไม่ได้แสดงวิธีการติดตั้งสำหรับระบบปฏิบัติการ Windows หากคุณใช้ Windows แนะนำให้ทำตามวิธีการลงด้วย Colab notebook หากคุณใช้ Linux หรือ macOS คุณสามารถทำตามวิธีใดก็ได้

หากคุณจะทำตามตัวอย่างในคอร์สนี้ คุณจำเป็นต้องมีบัญชี Hugging Face หากยังไม่มีบัญชี คุณสามารถ [สร้างบัญชีใหม่ที่นี่](https://huggingface.co/join)


## การใช้งาน Colab notebook (หรือเรียกว่า Google Colab)

การติดตั้งโดยใช้ Colab notebook เป็นวิธีการติดตั้งที่ง่ายที่สุด เพียงแค่คุณเปิดเว็บบราวเซอร์ เช่น Google Chrome, Microsoft Edge, Mozilla Firefox, Brave, หรือ Safari ก็สามารถใช้งานได้เลย

หากคุณยังไม่เคยใช้ Colab เราแนะนำให้คุณเริ่มต้นจาก [แนะนำการใช้งาน Colab](https://colab.research.google.com/notebooks/intro.ipynb) โดย Colab อนุญาตให้คุณใช้ฮาร์ดแวร์เพิ่มความเร็ว เช่น GPU หรือ TPU ได้ฟรีสำหรับงานเล็ก ๆ

เมื่อคุณคุ้นเคยกับการใช้งาน Colab แล้ว มาสร้าง notebook ใหม่กัน ผลจะออกมาหน้าตาเหมือนด้านล่าง:

<div class="flex justify-center">
<img src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter0/new_colab.png" alt="An empty colab notebook" width="80%"/>
</div>

ขั้นตอนต่อไป คือ การติดตั้ง library ที่ต้องใช้งานในคอร์สนี้ โดยเราจะใช้คำสั่ง `pip` ซึ่งเป็นตัวจัดการ package ใน Python เพื่อใช้ในการติดตั้ง โดยใน notebook นั้น คุณสามารถใช้งานคำสั่งระบบได้ด้วยการใส่ตัวอักษร `!` ด้านหน้าคำสั่งได้ ดังนั้นคุณสามารถติดตั้ง library 🤗 Transformers ด้วยคำสั่งดังต่อไปนี้:

```
!pip install transformers
```

คุณสามารถตรวจสอบว่าได้ติดตั้ง package เรียบร้อยแล้วหรือไม่ด้วยการ import เข้าไปใน Python ด้วยคำสั่งดังต่อไปนี้:

```
import transformers
```

<div class="flex justify-center">
<img src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter0/install.gif" alt="A gif showing the result of the two commands above: installation and import" width="80%"/>
</div>

ขั้นตอนนี้เป็นการติดตั้ง 🤗 Transformers แบบเวอร์ชั่นเล็กไปก่อน แต่ยังไม่ได้ติดตั้ง framework ใด ๆ ที่เกี่ยวข้องกับ machine learning เช่น PyTorch หรือ TensorFlow เนื่องจากเราต้องใช้ feature ต่าง ๆ ของ library เราจึงแนะนำให้ติดตั้งเวอร์ชันพัฒนาซึ่งมาพร้อมกับ library อื่น ๆ ที่จำเป็น(หรือเรียกว่า dependency) เพื่อให้ครอบคลุมการใช้งานทั้งหมด ด้วยคำสั่งดังต่อไปนี้

```
!pip install transformers[sentencepiece]
```

ขั้นตอนนี้จะใช้เวลานานนิดหน่อย แต่เมื่อจบแล้วก็ถือเป็นอันเสร็จสิ้น คุณพร้อมจะเริ่มใช้งานโค้ดต่าง ๆ ในคอร์สนี้ได้แล้ว!


## การใช้งานสิ่งแวดล้อมจำลองใน Python (หรือเรียกว่า Python virtual environment)

หากคุณถนัดการใช้งาน Python virtual environment มากกว่า ขั้นตอนแรกที่ต้องทำคือการติดตั้ง Python ลงบนเครื่องของคุณ เราแนะนำให้ทำตาม [ขั้นตอนนี้](https://realpython.com/installing-python/)

เมื่อคุณติดตั้ง Python เสร็จเรียบร้อย คุณสามารถรันคำสั่ง Python ที่ terminal ของคุณได้ โดยใช้คำสั่งดังต่อไปนี้: `python --version` หากคำสั่งนี้แสดงผลออกมาเป็น version ของ Python แสดงว่าระบบได้ติดตั้ง Python ลงบนเครื่องของคุณเรียบร้อยแล้วจริง ๆ

เมื่อคุณใช้คำสั่ง Python ที่ terminal เช่น `python --version` ตัวโปรแกรมจะไปเรียก Python "ชุดหลัก"จากระบบของคุณ เราไม่แนะนำให้คุณติดตั้ง package ใด ๆ ลงบน Python "ชุดหลัก" ดังกล่าว แต่ให้ใช้ในการสร้าง environment แยกออกมาในแต่ละการใช้งาน ดังนั้น แต่ละงานจะมี package และ dependency ของตนเอง ทำให้คุณไม่ต้องกังวลกับปัญหาใช้งานไม่ได้เพราะเวอร์ชันไม่ตรงเพราะไปชนกับการใช้งานอื่น ๆ

สำหรับ Python แล้ว กระบวนการนี้สามารถทำได้โดยใช้ [*virtual environment*](https://docs.python.org/3/tutorial/venv.html) ซึ่งเป็นการเก็บ directory ทั้งหมดในการติดตั้ง package ที่ต้องการในเวอร์ชันที่เราใช้งาน การสร้าง virtual environment สามารถทำได้หลายวิธี แต่เราจะใช้ package อย่างเป็นทางการจาก Python ชื่อว่า [`venv`](https://docs.python.org/3/library/venv.html#module-venv).

ขั้นแรกให้สร้าง directory สำหรับการใช้งาน เช่น หากคุณต้องการสร้าง directory ใหม่ ชื่อว่า *transformer-course* ที่ root ของ home directory สามารถใช้คำสั่งดังต่อไปนี้:

```
mkdir ~/transformers-course
cd ~/transformers-course
```

ภายใน directory นี้ ให้สร้าง virtual environment โดยใช้โมดูล `venv` ด้วยคำสั่งดังต่อไปนี้:

```
python -m venv .env
```

คุณจะพบ directory ชื่อ *.env* ใน directory ที่เคยว่างเปล่าของคุณ ด้วยคำสั่งดังต่อไปนี้:

```
ls -a
```

```out
. .. .env
```

คุณสามารถเข้าและออก virtual environment ได้ด้วยคำสั่ง `activate` และ `deactivate` ดังต่อไปนี้:

```
# Activate the virtual environment
source .env/bin/activate

# Deactivate the virtual environment
source .env/bin/deactivate
```

คุณสามารถตรวจสอบได้ว่าอยู่ใน environment ใดได้ด้วยคำสั่ง `which python` ระบบจะแสดงผล environment ที่คุณกำลังใช้งานอยู่

```
which python
```

```out
/home/<user>/transformers-course/.env/bin/python
```

### การติดตั้ง dependency

ดังที่แสดงไว้ข้างต้นในส่วนของการใช้งาน Google Colab คุณจำเป็นต้องติดตั้ง package ต่าง ๆ เพื่อให้ใช้งานได้ โดยคุณสามารถติดตั้งเวอร์ชันพัฒนาของ 🤗 Transformers โดยใช้คำสั่ง `pip` ดังต่อไปนี้:

```
pip install "transformers[sentencepiece]"
```

จากนี้ก็เป็นอันเสร็จสิ้น คุณพร้อมสำหรับการเริ่มต้นแล้ว!
Loading