From d34c1bc5f8e8a2e7dbdbe9d2e552d8fc1b50390c Mon Sep 17 00:00:00 2001 From: "jomariya.son@gmail.com" Date: Fri, 1 Apr 2022 19:35:07 +0700 Subject: [PATCH 01/12] Translated chapter4/1 --- chapters/th/_toctree.yml | 15 + chapters/th/_toctree.yml.bak | 15 + chapters/th/chapter4/1.mdx | 17 + chapters/th/chapter4/1.mdx.bak | 17 + chapters/th/chapter4/2.mdx | 96 +++++ chapters/th/chapter4/3.mdx | 641 +++++++++++++++++++++++++++++++++ chapters/th/chapter4/4.mdx | 82 +++++ chapters/th/chapter4/5.mdx | 7 + chapters/th/chapter4/6.mdx | 223 ++++++++++++ 9 files changed, 1113 insertions(+) create mode 100644 chapters/th/_toctree.yml create mode 100644 chapters/th/_toctree.yml.bak create mode 100644 chapters/th/chapter4/1.mdx create mode 100644 chapters/th/chapter4/1.mdx.bak create mode 100644 chapters/th/chapter4/2.mdx create mode 100644 chapters/th/chapter4/3.mdx create mode 100644 chapters/th/chapter4/4.mdx create mode 100644 chapters/th/chapter4/5.mdx create mode 100644 chapters/th/chapter4/6.mdx diff --git a/chapters/th/_toctree.yml b/chapters/th/_toctree.yml new file mode 100644 index 000000000..8eb9239d6 --- /dev/null +++ b/chapters/th/_toctree.yml @@ -0,0 +1,15 @@ +- title: 4. การแบ่งปันโมเดลและ tokenizers + sections: + - local: chapter4/1 + title: Hugging Face Hub + - local: chapter4/2 + title: การใช้งานโมเดลที่ผ่านการเทรนมาแล้ว (pretrained models) + - local: chapter4/3 + title: การแบ่งปันโมเดลที่ผ่านการเทรนมาแล้ว (pretrained models) + - local: chapter4/4 + title: การสร้างการ์ดโมเดล (model card) + - local: chapter4/5 + title: จบส่วนที่ 1! + - local: chapter4/6 + title: คำถามท้ายบท + quiz: 4 \ No newline at end of file diff --git a/chapters/th/_toctree.yml.bak b/chapters/th/_toctree.yml.bak new file mode 100644 index 000000000..0edeb993b --- /dev/null +++ b/chapters/th/_toctree.yml.bak @@ -0,0 +1,15 @@ +- title: 4. การแบ่งปันโมเดลและ tokenizers + sections: + - local: chapter4/1 + title: The Hugging Face Hub + - local: chapter4/2 + title: การใช้งานโมเดลที่ผ่านการเทรนมาแล้ว (pretrained models) + - local: chapter4/3 + title: การแบ่งปันโมเดลที่ผ่านการเทรนมาแล้ว (pretrained models) + - local: chapter4/4 + title: การสร้างการ์ดโมเดล (model card) + - local: chapter4/5 + title: จบส่วนที่ 1! + - local: chapter4/6 + title: คำถามท้ายบท + quiz: 4 \ No newline at end of file diff --git a/chapters/th/chapter4/1.mdx b/chapters/th/chapter4/1.mdx new file mode 100644 index 000000000..d2f5edb4c --- /dev/null +++ b/chapters/th/chapter4/1.mdx @@ -0,0 +1,17 @@ +# Hugging Face Hub + +[Hugging Face Hub](https://huggingface.co/) –- เว็บไซต์หลักของเรา –- เป็นแพลตฟอร์มกลางที่ทุกคนสามารถค้นหาโมเดลและชุดข้อมูลที่ล้ำสมัยที่สุด (state-of-the-art) และสามารถนำไปใช้งาน รวมถึงมีส่วนร่วมได้ เรามีโมเดลที่เปิดให้ใช้ได้อย่างเป็นสาธารณะที่หลากหลายมากกว่า 10,000 โมเดลให้เลือกใช้ ซึ่งในบทนี้เราจะมาเจาะลึกลงในเรื่องของโมเดล และเราจะพูดถึงชุดข้อมูลในบทที่ 5 + +โมเดลใน hub ของเราไม่ได้มีแค่ 🤗 Transformers หรือ NLP เท่านั้น ยังมีโมเดลจาก [Flair](https://github.com/flairNLP/flair) และ [AllenNLP](https://github.com/allenai/allennlp) สำหรับงาน NLP [Asteroid](https://github.com/asteroid-team/asteroid) และ [pyannote](https://github.com/pyannote/pyannote-audio) สำหรับงานเสียง และ [timm](https://github.com/rwightman/pytorch-image-models) สำหรับงานภาพ และอื่นๆอีกมากมาย + +โมเดลเหล่านี้ถูกเก็บไว้ในรูปแบบของ Git repository ซึ่งนั่นสามารถทำให้เกิดการกำหนดเวอร์ชั่น (versioning) และการทำซ้ำได้ (reproducibility) การแบ่งปันโมเดลบน hub นั้นหมายถึงการปล่อยโมเดลสู่ชุมชน และทำให้ผู้คนสามารถเข้าถึงโมเดลได้อย่างง่ายดาย รวมถึงช่วยกำจัดความจำเป็นในการเทรนโมเดลด้วยตัวเอง และทำให้สามารถแบ่งปันและใช้งานได้ง่ายอีกด้วย + +มากไปกว่านั้นการแบ่งปันโมเดลบน hub ยังเป็นการปล่อย (deploy) API สำหรับใช้โมเดลนั้นในการทำนายผลด้วย ซึ่งทุกคนสามารถนำไปทดสอบใช้งานกับข้อมูลอินพุตที่กำหนดได้เอง (custom inputs) และใช้คู่กับเครื่องมือที่เหมาะสมได้โดยตรงจากหน้าเว็บไซต์ของโมเดลนั้นโดยไม่มีค่าใช้จ่าย + +ส่วนที่ดีที่สุดคือ การแบ่งปันและใช้โมเดลสาธารณะบน hub นั้นไม่มีค่าใช้จ่ายโดยสิ้นเชิง! ซึ่งเรามี [แผนแบบจ่าย](https://huggingface.co/pricing) ถ้าหากคุณต้องการจะแบ่งปันโมเดลอย่างเป็นส่วนตัว + +วีดีโอข้างล่างนี้แสดงวิธีการนำทางไปหน้าต่างๆใน hub + + + +ในส่วนนี้คุณจำเป็นที่จะต้องมีบัญชี huggingface.co เพื่อที่จะทำตาม เพราะเราจะมีการสร้างและจัดการ repositories บน Hugging Face Hub [สร้างบัญชี](https://huggingface.co/join) \ No newline at end of file diff --git a/chapters/th/chapter4/1.mdx.bak b/chapters/th/chapter4/1.mdx.bak new file mode 100644 index 000000000..5b3a7f706 --- /dev/null +++ b/chapters/th/chapter4/1.mdx.bak @@ -0,0 +1,17 @@ +# The Hugging Face Hub + +The [Hugging Face Hub](https://huggingface.co/) –- our main website –- is a central platform that enables anyone to discover, use, and contribute new state-of-the-art models and datasets. It hosts a wide variety of models, with more than 10,000 publicly available. We'll focus on the models in this chapter, and take a look at the datasets in Chapter 5. + +The models in the Hub are not limited to 🤗 Transformers or even NLP. There are models from [Flair](https://github.com/flairNLP/flair) and [AllenNLP](https://github.com/allenai/allennlp) for NLP, [Asteroid](https://github.com/asteroid-team/asteroid) and [pyannote](https://github.com/pyannote/pyannote-audio) for speech, and [timm](https://github.com/rwightman/pytorch-image-models) for vision, to name a few. + +Each of these models is hosted as a Git repository, which allows versioning and reproducibility. Sharing a model on the Hub means opening it up to the community and making it accessible to anyone looking to easily use it, in turn eliminating their need to train a model on their own and simplifying sharing and usage. + +Additionally, sharing a model on the Hub automatically deploys a hosted Inference API for that model. Anyone in the community is free to test it out directly on the model's page, with custom inputs and appropriate widgets. + +The best part is that sharing and using any public model on the Hub is completely free! [Paid plans](https://huggingface.co/pricing) also exist if you wish to share models privately. + +The video below shows how to navigate the Hub. + + + +Having a huggingface.co account is required to follow along this part, as we'll be creating and managing repositories on the Hugging Face Hub: [create an account](https://huggingface.co/join) \ No newline at end of file diff --git a/chapters/th/chapter4/2.mdx b/chapters/th/chapter4/2.mdx new file mode 100644 index 000000000..9519cddac --- /dev/null +++ b/chapters/th/chapter4/2.mdx @@ -0,0 +1,96 @@ + + +# Using pretrained models + +{#if fw === 'pt'} + + + +{:else} + + + +{/if} + +The Model Hub makes selecting the appropriate model simple, so that using it in any downstream library can be done in a few lines of code. Let's take a look at how to actually use one of these models, and how to contribute back to the community. + +Let's say we're looking for a French-based model that can perform mask filling. + +
+Selecting the Camembert model. +
+ +We select the `camembert-base` checkpoint to try it out. The identifier `camembert-base` is all we need to start using it! As you've seen in previous chapters, we can instantiate it using the `pipeline()` function: + +```py +from transformers import pipeline + +camembert_fill_mask = pipeline("fill-mask", model="camembert-base") +results = camembert_fill_mask("Le camembert est :)") +``` + +```python out +[ + {'sequence': 'Le camembert est délicieux :)', 'score': 0.49091005325317383, 'token': 7200, 'token_str': 'délicieux'}, + {'sequence': 'Le camembert est excellent :)', 'score': 0.1055697426199913, 'token': 2183, 'token_str': 'excellent'}, + {'sequence': 'Le camembert est succulent :)', 'score': 0.03453313186764717, 'token': 26202, 'token_str': 'succulent'}, + {'sequence': 'Le camembert est meilleur :)', 'score': 0.0330314114689827, 'token': 528, 'token_str': 'meilleur'}, + {'sequence': 'Le camembert est parfait :)', 'score': 0.03007650189101696, 'token': 1654, 'token_str': 'parfait'} +] +``` + +As you can see, loading a model within a pipeline is extremely simple. The only thing you need to watch out for is that the chosen checkpoint is suitable for the task it's going to be used for. For example, here we are loading the `camembert-base` checkpoint in the `fill-mask` pipeline, which is completely fine. But if we were to load this checkpoint in the `text-classification` pipeline, the results would not make any sense because the head of `camembert-base` is not suitable for this task! We recommend using the task selector in the Hugging Face Hub interface in order to select the appropriate checkpoints: + +
+The task selector on the web interface. +
+ +You can also instantiate the checkpoint using the model architecture directly: + +{#if fw === 'pt'} +```py +from transformers import CamembertTokenizer, CamembertForMaskedLM + +tokenizer = CamembertTokenizer.from_pretrained("camembert-base") +model = CamembertForMaskedLM.from_pretrained("camembert-base") +``` + +However, we recommend using the [`Auto*` classes](https://huggingface.co/transformers/model_doc/auto.html?highlight=auto#auto-classes) instead, as these are by design architecture-agnostic. While the previous code sample limits users to checkpoints loadable in the CamemBERT architecture, using the `Auto*` classes makes switching checkpoints simple: + +```py +from transformers import AutoTokenizer, AutoModelForMaskedLM + +tokenizer = AutoTokenizer.from_pretrained("camembert-base") +model = AutoModelForMaskedLM.from_pretrained("camembert-base") +``` +{:else} +```py +from transformers import CamembertTokenizer, TFCamembertForMaskedLM + +tokenizer = CamembertTokenizer.from_pretrained("camembert-base") +model = TFCamembertForMaskedLM.from_pretrained("camembert-base") +``` + +However, we recommend using the [`TFAuto*` classes](https://huggingface.co/transformers/model_doc/auto.html?highlight=auto#auto-classes) instead, as these are by design architecture-agnostic. While the previous code sample limits users to checkpoints loadable in the CamemBERT architecture, using the `TFAuto*` classes makes switching checkpoints simple: + +```py +from transformers import AutoTokenizer, TFAutoModelForMaskedLM + +tokenizer = AutoTokenizer.from_pretrained("camembert-base") +model = TFAutoModelForMaskedLM.from_pretrained("camembert-base") +``` +{/if} + + +When using a pretrained model, make sure to check how it was trained, on which datasets, its limits, and its biases. All of this information should be indicated on its model card. + diff --git a/chapters/th/chapter4/3.mdx b/chapters/th/chapter4/3.mdx new file mode 100644 index 000000000..a2dbc7ee8 --- /dev/null +++ b/chapters/th/chapter4/3.mdx @@ -0,0 +1,641 @@ + + +# Sharing pretrained models + +{#if fw === 'pt'} + + + +{:else} + + + +{/if} + +In the steps below, we'll take a look at the easiest ways to share pretrained models to the 🤗 Hub. There are tools and utilities available that make it simple to share and update models directly on the Hub, which we will explore below. + + + +We encourage all users that train models to contribute by sharing them with the community — sharing models, even when trained on very specific datasets, will help others, saving them time and compute resources and providing access to useful trained artifacts. In turn, you can benefit from the work that others have done! + +There are three ways to go about creating new model repositories: + +- Using the `push_to_hub` API +- Using the `huggingface_hub` Python library +- Using the web interface + +Once you've created a repository, you can upload files to it via git and git-lfs. We'll walk you through creating model repositories and uploading files to them in the following sections. + + +## Using the `push_to_hub` API + +{#if fw === 'pt'} + + + +{:else} + + + +{/if} + +The simplest way to upload files to the Hub is by leveraging the `push_to_hub` API. + +Before going further, you'll need to generate an authentication token so that the `huggingface_hub` API knows who you are and what namespaces you have write access to. Make sure you are in an environment where you have `transformers` installed (see [Setup](/course/chapter0)). If you are in a notebook, you can use the following function to login: + +```python +from huggingface_hub import notebook_login + +notebook_login() +``` + +In a terminal, you can run: + +```bash +huggingface-cli login +``` + +In both cases, you should be prompted for your username and password, which are the same ones you use to log in to the Hub. If you do not have a Hub profile yet, you should create one [here](https://huggingface.co/join). + +Great! You now have your authentication token stored in your cache folder. Let's create some repositories! + +{#if fw === 'pt'} + +If you have played around with the `Trainer` API to train a model, the easiest way to upload it to the Hub is to set `push_to_hub=True` when you define your `TrainingArguments`: + +```py +from transformers import TrainingArguments + +training_args = TrainingArguments( + "bert-finetuned-mrpc", save_strategy="epoch", push_to_hub=True +) +``` + +When you call `trainer.train()`, the `Trainer` will then upload your model to the Hub each time it is saved (here every epoch) in a repository in your namespace. That repository will be named like the output directory you picked (here `bert-finetuned-mrpc`) but you can choose a different name with `hub_model_id = "a_different_name"`. + +To upload you model to an organization you are a member of, just pass it with `hub_model_id = "my_organization/my_repo_name"`. + +Once your training is finished, you should do a final `trainer.push_to_hub()` to upload the last version of your model. It will also generate a model card with all the relevant metadata, reporting the hyperparameters used and the evaluation results! Here is an example of the content you might find in a such a model card: + +
+ An example of an auto-generated model card. +
+ +{:else} + +If you are using Keras to train your model, the easiest way to upload it to the Hub is to pass along a `PushToHubCallback` when you call `model.fit()`: + +```py +from transformers import PushToHubCallback + +callback = PushToHubCallback( + "bert-finetuned-mrpc", save_strategy="epoch", tokenizer=tokenizer +) +``` + +Then you should add `callbacks=[callback]` in your call to `model.fit()`. The callback will then upload your model to the Hub each time it is saved (here every epoch) in a repository in your namespace. That repository will be named like the output directory you picked (here `bert-finetuned-mrpc`) but you can choose a different name with `hub_model_id = "a_different_name"`. + +To upload you model to an organization you are a member of, just pass it with `hub_model_id = "my_organization/my_repo_name"`. + +{/if} + +At a lower level, accessing the Model Hub can be done directly on models, tokenizers, and configuration objects via their `push_to_hub()` method. This method takes care of both the repository creation and pushing the model and tokenizer files directly to the repository. No manual handling is required, unlike with the API we'll see below. + +To get an idea of how it works, let's first initialize a model and a tokenizer: + +{#if fw === 'pt'} +```py +from transformers import AutoModelForMaskedLM, AutoTokenizer + +checkpoint = "camembert-base" + +model = AutoModelForMaskedLM.from_pretrained(checkpoint) +tokenizer = AutoTokenizer.from_pretrained(checkpoint) +``` +{:else} +```py +from transformers import TFAutoModelForMaskedLM, AutoTokenizer + +checkpoint = "camembert-base" + +model = TFAutoModelForMaskedLM.from_pretrained(checkpoint) +tokenizer = AutoTokenizer.from_pretrained(checkpoint) +``` +{/if} + +You're free to do whatever you want with these — add tokens to the tokenizer, train the model, fine-tune it. Once you're happy with the resulting model, weights, and tokenizer, you can leverage the `push_to_hub()` method directly available on the `model` object: + +```py +model.push_to_hub("dummy-model") +``` + +This will create the new repository `dummy-model` in your profile, and populate it with your model files. +Do the same with the tokenizer, so that all the files are now available in this repository: + +```py +tokenizer.push_to_hub("dummy-model") +``` + +If you belong to an organization, simply specify the `organization` argument to upload to that organization's namespace: + +```py +tokenizer.push_to_hub("dummy-model", organization="huggingface") +``` + +If you wish to use a specific Hugging Face token, you're free to specify it to the `push_to_hub()` method as well: + +```py +tokenizer.push_to_hub("dummy-model", organization="huggingface", use_auth_token="") +``` + +Now head to the Model Hub to find your newly uploaded model: *https://huggingface.co/user-or-organization/dummy-model*. + +Click on the "Files and versions" tab, and you should see the files visible in the following screenshot: + +{#if fw === 'pt'} +
+Dummy model containing both the tokenizer and model files. +
+{:else} +
+Dummy model containing both the tokenizer and model files. +
+{/if} + + + +✏️ **Try it out!** Take the model and tokenizer associated with the `bert-base-cased` checkpoint and upload them to a repo in your namespace using the `push_to_hub()` method. Double-check that the repo appears properly on your page before deleting it. + + + +As you've seen, the `push_to_hub()` method accepts several arguments, making it possible to upload to a specific repository or organization namespace, or to use a different API token. We recommend you take a look at the method specification available directly in the [🤗 Transformers documentation](https://huggingface.co/transformers/model_sharing.html) to get an idea of what is possible. + +The `push_to_hub()` method is backed by the [`huggingface_hub`](https://github.com/huggingface/huggingface_hub) Python package, which offers a direct API to the Hugging Face Hub. It's integrated within 🤗 Transformers and several other machine learning libraries, like [`allenlp`](https://github.com/allenai/allennlp). Although we focus on the 🤗 Transformers integration in this chapter, integrating it into your own code or library is simple. + +Jump to the last section to see how to upload files to your newly created repository! + +## Using the `huggingface_hub` Python library + +The `huggingface_hub` Python library is a package which offers a set of tools for the model and datasets hubs. It provides simple methods and classes for common tasks like +getting information about repositories on the hub and managing them. It provides simple APIs that work on top of git to manage those repositories' content and to integrate the Hub +in your projects and libraries. + +Similarly to using the `push_to_hub` API, this will require you to have your API token saved in your cache. In order to do this, you will need to use the `login` command from the CLI, as mentioned in the previous section (again, make sure to prepend these commands with the `!` character if running in Google Colab): + +```bash +huggingface-cli login +``` + +The `huggingface_hub` package offers several methods and classes which are useful for our purpose. Firstly, there are a few methods to manage repository creation, deletion, and others: + +```python no-format +from huggingface_hub import ( + # User management + login, + logout, + whoami, + + # Repository creation and management + create_repo, + delete_repo, + update_repo_visibility, + + # And some methods to retrieve/change information about the content + list_models, + list_datasets, + list_metrics, + list_repo_files, + upload_file, + delete_file, +) +``` + + +Additionally, it offers the very powerful `Repository` class to manage a local repository. We will explore these methods and that class in the next few section to understand how to leverage them. + +The `create_repo` method can be used to create a new repository on the hub: + +```py +from huggingface_hub import create_repo + +create_repo("dummy-model") +``` + +This will create the repository `dummy-model` in your namespace. If you like, you can specify which organization the repository should belong to using the `organization` argument: + +```py +from huggingface_hub import create_repo + +create_repo("dummy-model", organization="huggingface") +``` + +This will create the `dummy-model` repository in the `huggingface` namespace, assuming you belong to that organization. +Other arguments which may be useful are: + +- `private`, in order to specify if the repository should be visible from others or not. +- `token`, if you would like to override the token stored in your cache by a given token. +- `repo_type`, if you would like to create a `dataset` or a `space` instead of a model. Accepted values are `"dataset"` and `"space"`. + +Once the repository is created, we should add files to it! Jump to the next section to see the three ways this can be handled. + + +## Using the web interface + +The web interface offers tools to manage repositories directly in the Hub. Using the interface, you can easily create repositories, add files (even large ones!), explore models, visualize diffs, and much more. + +To create a new repository, visit [huggingface.co/new](https://huggingface.co/new): + +
+Page showcasing the model used for the creation of a new model repository. +
+ +First, specify the owner of the repository: this can be either you or any of the organizations you're affiliated with. If you choose an organization, the model will be featured on the organization's page and every member of the organization will have the ability to contribute to the repository. + +Next, enter your model's name. This will also be the name of the repository. Finally, you can specify whether you want your model to be public or private. Private models are hidden from public view. + +After creating your model repository, you should see a page like this: + +
+An empty model page after creating a new repository. +
+ +This is where your model will be hosted. To start populating it, you can add a README file directly from the web interface. + +
+The README file showing the Markdown capabilities. +
+ +The README file is in Markdown — feel free to go wild with it! The third part of this chapter is dedicated to building a model card. These are of prime importance in bringing value to your model, as they're where you tell others what it can do. + +If you look at the "Files and versions" tab, you'll see that there aren't many files there yet — just the *README.md* you just created and the *.gitattributes* file that keeps track of large files. + +
+The 'Files and versions' tab only shows the .gitattributes and README.md files. +
+ +We'll take a look at how to add some new files next. + +## Uploading the model files + +The system to manage files on the Hugging Face Hub is based on git for regular files, and git-lfs (which stands for [Git Large File Storage](https://git-lfs.github.com/)) for larger files. + +In the next section, we go over three different ways of uploading files to the Hub: through `huggingface_hub` and through git commands. + +### The `upload_file` approach + +Using `upload_file` does not require git and git-lfs to be installed on your system. It pushes files directly to the 🤗 Hub using HTTP POST requests. A limitation of this approach is that it doesn't handle files that are larger than 5GB in size. +If your files are larger than 5GB, please follow the two other methods detailed below. + +The API may be used as follows: + +```py +from huggingface_hub import upload_file + +upload_file( + "/config.json", + path_in_repo="config.json", + repo_id="/dummy-model", +) +``` + +This will upload the file `config.json` available at `` to the root of the repository as `config.json`, to the `dummy-model` repository. +Other arguments which may be useful are: + +- `token`, if you would like to override the token stored in your cache by a given token. +- `repo_type`, if you would like to upload to a `dataset` or a `space` instead of a model. Accepted values are `"dataset"` and `"space"`. + + +### The `Repository` class + +The `Repository` class manages a local repository in a git-like manner. It abstracts most of the pain points one may have with git to provide all features that we require. + +Using this class requires having git and git-lfs installed, so make sure you have git-lfs installed (see [here](https://git-lfs.github.com/) for installation instructions) and set up before you begin. + +In order to start playing around with the repository we have just created, we can start by initialising it into a local folder by cloning the remote repository: + +```py +from huggingface_hub import Repository + +repo = Repository("", clone_from="/dummy-model") +``` + +This created the folder `` in our working directory. This folder only contains the `.gitattributes` file as that's the only file created when instantiating the repository through `create_repo`. + +From this point on, we may leverage several of the traditional git methods: + +```py +repo.git_pull() +repo.git_add() +repo.git_commit() +repo.git_push() +repo.git_tag() +``` + +And others! We recommend taking a look at the `Repository` documentation available [here](https://github.com/huggingface/huggingface_hub/tree/main/src/huggingface_hub#advanced-programmatic-repository-management) for an overview of all available methods. + +At present, we have a model and a tokenizer that we would like to push to the hub. We have successfully cloned the repository, we can therefore save the files within that repository. + +We first make sure that our local clone is up to date by pulling the latest changes: + +```py +repo.git_pull() +``` + +Once that is done, we save the model and tokenizer files: + +```py +model.save_pretrained("") +tokenizer.save_pretrained("") +``` + +The `` now contains all the model and tokenizer files. We follow the usual git workflow by adding files to the staging area, committing them and pushing them to the hub: + +```py +repo.git_add() +repo.git_commit("Add model and tokenizer files") +repo.git_push() +``` + +Congratulations! You just pushed your first files on the hub. + +### The git-based approach + +This is the very barebones approach to uploading files: we'll do so with git and git-lfs directly. Most of the difficulty is abstracted away by previous approaches, but there are a few caveats with the following method so we'll follow a more complex use-case. + +Using this class requires having git and git-lfs installed, so make sure you have [git-lfs](https://git-lfs.github.com/) installed (see here for installation instructions) and set up before you begin. + +First start by initializing git-lfs: + +```bash +git lfs install +``` + +```bash +Updated git hooks. +Git LFS initialized. +``` + +Once that's done, the first step is to clone your model repository: + +```bash +git clone https://huggingface.co// +``` + +My username is `lysandre` and I've used the model name `dummy`, so for me the command ends up looking like the following: + +``` +git clone https://huggingface.co/lysandre/dummy +``` + +I now have a folder named *dummy* in my working directory. I can `cd` into the folder and have a look at the contents: + +```bash +cd dummy && ls +``` + +```bash +README.md +``` + +If you just created your repository using Hugging Face Hub's `create_repo` method, this folder should only contain a hidden `.gitattributes` file. If you followed the instructions in the previous section to create a repository using the web interface, the folder should contain a single *README.md* file alongside the hidden `.gitattributes` file, as shown here. + +Adding a regular-sized file, such as a configuration file, a vocabulary file, or basically any file under a few megabytes, is done exactly as one would do it in any git-based system. However, bigger files must be registered through git-lfs in order to push them to *huggingface.co*. + +Let's go back to Python for a bit to generate a model and tokenizer that we'd like to commit to our dummy repository: + +{#if fw === 'pt'} +```py +from transformers import AutoModelForMaskedLM, AutoTokenizer + +checkpoint = "camembert-base" + +model = AutoModelForMaskedLM.from_pretrained(checkpoint) +tokenizer = AutoTokenizer.from_pretrained(checkpoint) + +# Do whatever with the model, train it, fine-tune it... + +model.save_pretrained("") +tokenizer.save_pretrained("") +``` +{:else} +```py +from transformers import TFAutoModelForMaskedLM, AutoTokenizer + +checkpoint = "camembert-base" + +model = TFAutoModelForMaskedLM.from_pretrained(checkpoint) +tokenizer = AutoTokenizer.from_pretrained(checkpoint) + +# Do whatever with the model, train it, fine-tune it... + +model.save_pretrained("") +tokenizer.save_pretrained("") +``` +{/if} + +Now that we've saved some model and tokenizer artifacts, let's take another look at the *dummy* folder: + +```bash +ls +``` + +{#if fw === 'pt'} +```bash +config.json pytorch_model.bin README.md sentencepiece.bpe.model special_tokens_map.json tokenizer_config.json tokenizer.json +``` + +If you look at the file sizes (for example, with `ls -lh`), you should see that the model state dict file (*pytorch_model.bin*) is the only outlier, at more than 400 MB. + +{:else} +```bash +config.json README.md sentencepiece.bpe.model special_tokens_map.json tf_model.h5 tokenizer_config.json tokenizer.json +``` + +If you look at the file sizes (for example, with `ls -lh`), you should see that the model state dict file (*t5_model.h5*) is the only outlier, at more than 400 MB. + +{/if} + + +✏️ When creating the repository from the web interface, the *.gitattributes* file is automatically set up to consider files with certain extensions, such as *.bin* and *.h5*, as large files, and git-lfs will track them with no necessary setup on your side. + + +We can now go ahead and proceed like we would usually do with traditional Git repositories. We can add all the files to Git's staging environment using the `git add` command: + +```bash +git add . +``` + +We can then have a look at the files that are currently staged: + +```bash +git status +``` + +{#if fw === 'pt'} +```bash +On branch main +Your branch is up to date with 'origin/main'. + +Changes to be committed: + (use "git restore --staged ..." to unstage) + modified: .gitattributes + new file: config.json + new file: pytorch_model.bin + new file: sentencepiece.bpe.model + new file: special_tokens_map.json + new file: tokenizer.json + new file: tokenizer_config.json +``` +{:else} +```bash +On branch main +Your branch is up to date with 'origin/main'. + +Changes to be committed: + (use "git restore --staged ..." to unstage) + modified: .gitattributes + new file: config.json + new file: sentencepiece.bpe.model + new file: special_tokens_map.json + new file: tf_model.h5 + new file: tokenizer.json + new file: tokenizer_config.json +``` +{/if} + +Similarly, we can make sure that git-lfs is tracking the correct files by using its `status` command: + +```bash +git lfs status +``` + +{#if fw === 'pt'} +```bash +On branch main +Objects to be pushed to origin/main: + + +Objects to be committed: + + config.json (Git: bc20ff2) + pytorch_model.bin (LFS: 35686c2) + sentencepiece.bpe.model (LFS: 988bc5a) + special_tokens_map.json (Git: cb23931) + tokenizer.json (Git: 851ff3e) + tokenizer_config.json (Git: f0f7783) + +Objects not staged for commit: + + +``` + +We can see that all files have `Git` as a handler, except *pytorch_model.bin* and *sentencepiece.bpe.model*, which have `LFS`. Great! + +{:else} +```bash +On branch main +Objects to be pushed to origin/main: + + +Objects to be committed: + + config.json (Git: bc20ff2) + sentencepiece.bpe.model (LFS: 988bc5a) + special_tokens_map.json (Git: cb23931) + tf_model.h5 (LFS: 86fce29) + tokenizer.json (Git: 851ff3e) + tokenizer_config.json (Git: f0f7783) + +Objects not staged for commit: + + +``` + +We can see that all files have `Git` as a handler, except *t5_model.h5*, which has `LFS`. Great! + +{/if} + +Let's proceed to the final steps, committing and pushing to the *huggingface.co* remote repository: + +```bash +git commit -m "First model version" +``` + +{#if fw === 'pt'} +```bash +[main b08aab1] First model version + 7 files changed, 29027 insertions(+) + 6 files changed, 36 insertions(+) + create mode 100644 config.json + create mode 100644 pytorch_model.bin + create mode 100644 sentencepiece.bpe.model + create mode 100644 special_tokens_map.json + create mode 100644 tokenizer.json + create mode 100644 tokenizer_config.json +``` +{:else} +```bash +[main b08aab1] First model version + 6 files changed, 36 insertions(+) + create mode 100644 config.json + create mode 100644 sentencepiece.bpe.model + create mode 100644 special_tokens_map.json + create mode 100644 tf_model.h5 + create mode 100644 tokenizer.json + create mode 100644 tokenizer_config.json +``` +{/if} + +Pushing can take a bit of time, depending on the speed of your internet connection and the size of your files: + +```bash +git push +``` + +```bash +Uploading LFS objects: 100% (1/1), 433 MB | 1.3 MB/s, done. +Enumerating objects: 11, done. +Counting objects: 100% (11/11), done. +Delta compression using up to 12 threads +Compressing objects: 100% (9/9), done. +Writing objects: 100% (9/9), 288.27 KiB | 6.27 MiB/s, done. +Total 9 (delta 1), reused 0 (delta 0), pack-reused 0 +To https://huggingface.co/lysandre/dummy + 891b41d..b08aab1 main -> main +``` + +{#if fw === 'pt'} +If we take a look at the model repository when this is finished, we can see all the recently added files: + +
+The 'Files and versions' tab now contains all the recently uploaded files. +
+ +The UI allows you to explore the model files and commits and to see the diff introduced by each commit: + +
+The diff introduced by the recent commit. +
+{:else} +If we take a look at the model repository when this is finished, we can see all the recently added files: + +
+The 'Files and versions' tab now contains all the recently uploaded files. +
+ +The UI allows you to explore the model files and commits and to see the diff introduced by each commit: + +
+The diff introduced by the recent commit. +
+{/if} diff --git a/chapters/th/chapter4/4.mdx b/chapters/th/chapter4/4.mdx new file mode 100644 index 000000000..8d9a75817 --- /dev/null +++ b/chapters/th/chapter4/4.mdx @@ -0,0 +1,82 @@ +# Building a model card + +The model card is a file which is arguably as important as the model and tokenizer files in a model repository. It is the central definition of the model, ensuring reusability by fellow community members and reproducibility of results, and providing a platform on which other members may build their artifacts. + +Documenting the training and evaluation process helps others understand what to expect of a model — and providing sufficient information regarding the data that was used and the preprocessing and postprocessing that were done ensures that the limitations, biases, and contexts in which the model is and is not useful can be identified and understood. + +Therefore, creating a model card that clearly defines your model is a very important step. Here, we provide some tips that will help you with this. Creating the model card is done through the *README.md* file you saw earlier, which is a Markdown file. + +The "model card" concept originates from a research direction from Google, first shared in the paper ["Model Cards for Model Reporting"](https://arxiv.org/abs/1810.03993) by Margaret Mitchell et al. A lot of information contained here is based on that paper, and we recommend you take a look at it to understand why model cards are so important in a world that values reproducibility, reusability, and fairness. + +The model card usually starts with a very brief, high-level overview of what the model is for, followed by additional details in the following sections: + +- Model description +- Intended uses & limitations +- How to use +- Limitations and bias +- Training data +- Training procedure +- Evaluation results + +Let's take a look at what each of these sections should contain. + +### Model description + +The model description provides basic details about the model. This includes the architecture, version, if it was introduced in a paper, if an original implementation is available, the author, and general information about the model. Any copyright should be attributed here. General information about training procedures, parameters, and important disclaimers can also be mentioned in this section. + +### Intended uses & limitations + +Here you describe the use cases the model is intended for, including the languages, fields, and domains where it can be applied. This section of the model card can also document areas that are known to be out of scope for the model, or where it is likely to perform suboptimally. + +### How to use + +This section should include some examples of how to use the model. This can showcase usage of the `pipeline()` function, usage of the model and tokenizer classes, and any other code you think might be helpful. + +### Training data + +This part should indicate which dataset(s) the model was trained on. A brief description of the dataset(s) is also welcome. + +### Training procedure + +In this section you should describe all the relevant aspects of training that are useful from a reproducibility perspective. This includes any preprocessing and postprocessing that were done on the data, as well as details such as the number of epochs the model was trained for, the batch size, the learning rate, and so on. + +### Variable and metrics + +Here you should describe the metrics you use for evaluation, and the different factors you are mesuring. Mentioning which metric(s) were used, on which dataset and which dataset split, makes it easy to compare you model's performance compared to that of other models. These should be informed by the previous sections, such as the intended users and use cases. + +### Evaluation results + +Finally, provide an indication of how well the model performs on the evaluation dataset. If the model uses a decision threshold, either provide the decision threshold used in the evaluation, or provide details on evaluation at different thresholds for the intended uses. + +## Example + +Check out the following for a few examples of well-crafted model cards: + +- [`bert-base-cased`](https://huggingface.co/bert-base-cased) +- [`gpt2`](https://huggingface.co/gpt2) +- [`distilbert`](https://huggingface.co/distilbert-base-uncased) + +More examples from different organizations and companies are available [here](https://github.com/huggingface/model_card/blob/master/examples.md). + +## Note + +Model cards are not a requirement when publishing models, and you don't need to include all of the sections described above when you make one. However, explicit documentation of the model can only benefit future users, so we recommend that you fill in as many of the sections as possible to the best of your knowledge and ability. + +## Model card metadata + +If you have done a little exploring of the Hugging Face Hub, you should have seen that some models belong to certain categories: you can filter them by tasks, languages, libraries, and more. The categories a model belongs to are identified according to the metadata you add in the model card header. + +For example, if you take a look at the [`camembert-base` model card](https://huggingface.co/camembert-base/blob/main/README.md), you should see the following lines in the model card header: + +``` +--- +language: fr +license: mit +datasets: +- oscar +--- +``` + +This metadata is parsed by the Hugging Face Hub, which then identifies this model as being a French model, with an MIT license, trained on the Oscar dataset. + +The [full model card specification](https://github.com/huggingface/hub-docs/blame/main/modelcard.md) allows specifying languages, licenses, tags, datasets, metrics, as well as the evaluation results the model obtained when training. diff --git a/chapters/th/chapter4/5.mdx b/chapters/th/chapter4/5.mdx new file mode 100644 index 000000000..9edff8a97 --- /dev/null +++ b/chapters/th/chapter4/5.mdx @@ -0,0 +1,7 @@ +# Part 1 completed! + +This is the end of the first part of the course! Part 2 will be released on November 15th with a big community event, see more information [here](https://huggingface.co/blog/course-launch-event). + +You should now be able to fine-tune a pretrained model on a text classification problem (single or pairs of sentences) and upload the result to the Model Hub. To make sure you mastered this first section, you should do exactly that on a problem that interests you (and not necessarily in English if you speak another language)! You can find help in the [Hugging Face forums](https://discuss.huggingface.co/) and share your project in [this topic](https://discuss.huggingface.co/t/share-your-projects/6803) once you're finished. + +We can't wait to see what you will build with this! diff --git a/chapters/th/chapter4/6.mdx b/chapters/th/chapter4/6.mdx new file mode 100644 index 000000000..6e968972f --- /dev/null +++ b/chapters/th/chapter4/6.mdx @@ -0,0 +1,223 @@ + + + + +# End-of-chapter quiz + +Let's test what you learned in this chapter! + +### 1. What are models on the Hub limited to? + + + +### 2. How can you manage models on the Hub? + +git-lfs for large files.", + correct: true + } + ]} +/> + +### 3. What can you do using the Hugging Face Hub web interface? + + + +### 4. What is a model card? + + + +### 5. Which of these objects of the 🤗 Transformers library can be directly shared on the Hub with `push_to_hub()`? + +{#if fw === 'pt'} +push_to_hub method, and using it will push all the tokenizer files (vocabulary, architecture of the tokenizer, etc.) to a given repo. That's not the only right answer, though!", + correct: true + }, + { + text: "A model configuration", + explain: "Right! All model configurations have the push_to_hub method, and using it will push them to a given repo. What else can you share?", + correct: true + }, + { + text: "A model", + explain: "Correct! All models have the push_to_hub method, and using it will push them and their configuration files to a given repo. That's not all you can share, though.", + correct: true + }, + { + text: "A Trainer", + explain: "That's right — the Trainer also implements the push_to_hub method, and using it will upload the model, its configuration, the tokenizer, and a model card draft to a given repo. Try another answer!", + correct: true + } + ]} +/> +{:else} +push_to_hub method, and using it will push all the tokenizer files (vocabulary, architecture of the tokenizer, etc.) to a given repo. That's not the only right answer, though!", + correct: true + }, + { + text: "A model configuration", + explain: "Right! All model configurations have the push_to_hub method, and using it will push them to a given repo. What else can you share?", + correct: true + }, + { + text: "A model", + explain: "Correct! All models have the push_to_hub method, and using it will push them and their configuration files to a given repo. That's not all you can share, though.", + correct: true + }, + { + text: "All of the above with a dedicated callback", + explain: "That's right — the PushToHubCallback will regularly send all of those objects to a repo during training.", + correct: true + } + ]} +/> +{/if} + +### 6. What is the first step when using the `push_to_hub()` method or the CLI tools? + + + +### 7. You're using a model and a tokenizer — how can you upload them to the Hub? + +huggingface_hub utility.", + explain: "Models and tokenizers already benefit from huggingface_hub utilities: no need for additional wrapping!" + }, + { + text: "By saving them to disk and calling transformers-cli upload-model", + explain: "The command upload-model does not exist." + } + ]} +/> + +### 8. Which git operations can you do with the `Repository` class? + +git_commit() method is there for that.", + correct: true + }, + { + text: "A pull", + explain: "That is the purpose of the git_pull() method.", + correct: true + }, + { + text: "A push", + explain: "The method git_push() does this.", + correct: true + }, + { + text: "A merge", + explain: "No, that operation will never be possible with this API." + } + ]} +/> From 5c45ec95d121406a13c86d74ae501e6acf2b8ae7 Mon Sep 17 00:00:00 2001 From: "jomariya.son@gmail.com" Date: Fri, 1 Apr 2022 22:54:12 +0700 Subject: [PATCH 02/12] Translated chapter4/2 --- chapters/th/_toctree.yml.bak | 15 --------------- chapters/th/chapter4/1.mdx | 2 +- chapters/th/chapter4/1.mdx.bak | 17 ----------------- chapters/th/chapter4/2.mdx | 18 +++++++++--------- 4 files changed, 10 insertions(+), 42 deletions(-) delete mode 100644 chapters/th/_toctree.yml.bak delete mode 100644 chapters/th/chapter4/1.mdx.bak diff --git a/chapters/th/_toctree.yml.bak b/chapters/th/_toctree.yml.bak deleted file mode 100644 index 0edeb993b..000000000 --- a/chapters/th/_toctree.yml.bak +++ /dev/null @@ -1,15 +0,0 @@ -- title: 4. การแบ่งปันโมเดลและ tokenizers - sections: - - local: chapter4/1 - title: The Hugging Face Hub - - local: chapter4/2 - title: การใช้งานโมเดลที่ผ่านการเทรนมาแล้ว (pretrained models) - - local: chapter4/3 - title: การแบ่งปันโมเดลที่ผ่านการเทรนมาแล้ว (pretrained models) - - local: chapter4/4 - title: การสร้างการ์ดโมเดล (model card) - - local: chapter4/5 - title: จบส่วนที่ 1! - - local: chapter4/6 - title: คำถามท้ายบท - quiz: 4 \ No newline at end of file diff --git a/chapters/th/chapter4/1.mdx b/chapters/th/chapter4/1.mdx index d2f5edb4c..8f9948fe2 100644 --- a/chapters/th/chapter4/1.mdx +++ b/chapters/th/chapter4/1.mdx @@ -14,4 +14,4 @@ -ในส่วนนี้คุณจำเป็นที่จะต้องมีบัญชี huggingface.co เพื่อที่จะทำตาม เพราะเราจะมีการสร้างและจัดการ repositories บน Hugging Face Hub [สร้างบัญชี](https://huggingface.co/join) \ No newline at end of file +ในส่วนนี้คุณจำเป็นที่จะต้องมีบัญชี huggingface.co เพื่อที่จะทำตาม เพราะเราจะมีการสร้างและจัดการ repositories บน Hugging Face Hub: [สร้างบัญชี](https://huggingface.co/join) \ No newline at end of file diff --git a/chapters/th/chapter4/1.mdx.bak b/chapters/th/chapter4/1.mdx.bak deleted file mode 100644 index 5b3a7f706..000000000 --- a/chapters/th/chapter4/1.mdx.bak +++ /dev/null @@ -1,17 +0,0 @@ -# The Hugging Face Hub - -The [Hugging Face Hub](https://huggingface.co/) –- our main website –- is a central platform that enables anyone to discover, use, and contribute new state-of-the-art models and datasets. It hosts a wide variety of models, with more than 10,000 publicly available. We'll focus on the models in this chapter, and take a look at the datasets in Chapter 5. - -The models in the Hub are not limited to 🤗 Transformers or even NLP. There are models from [Flair](https://github.com/flairNLP/flair) and [AllenNLP](https://github.com/allenai/allennlp) for NLP, [Asteroid](https://github.com/asteroid-team/asteroid) and [pyannote](https://github.com/pyannote/pyannote-audio) for speech, and [timm](https://github.com/rwightman/pytorch-image-models) for vision, to name a few. - -Each of these models is hosted as a Git repository, which allows versioning and reproducibility. Sharing a model on the Hub means opening it up to the community and making it accessible to anyone looking to easily use it, in turn eliminating their need to train a model on their own and simplifying sharing and usage. - -Additionally, sharing a model on the Hub automatically deploys a hosted Inference API for that model. Anyone in the community is free to test it out directly on the model's page, with custom inputs and appropriate widgets. - -The best part is that sharing and using any public model on the Hub is completely free! [Paid plans](https://huggingface.co/pricing) also exist if you wish to share models privately. - -The video below shows how to navigate the Hub. - - - -Having a huggingface.co account is required to follow along this part, as we'll be creating and managing repositories on the Hugging Face Hub: [create an account](https://huggingface.co/join) \ No newline at end of file diff --git a/chapters/th/chapter4/2.mdx b/chapters/th/chapter4/2.mdx index 9519cddac..22972bd41 100644 --- a/chapters/th/chapter4/2.mdx +++ b/chapters/th/chapter4/2.mdx @@ -1,6 +1,6 @@ -# Using pretrained models +# การใช้งานโมเดลที่ผ่านการเทรนมาแล้ว (pretrained models) {#if fw === 'pt'} @@ -22,15 +22,15 @@ {/if} -The Model Hub makes selecting the appropriate model simple, so that using it in any downstream library can be done in a few lines of code. Let's take a look at how to actually use one of these models, and how to contribute back to the community. +Model Hub ทำให้การเลือกใช้โมเดลที่เหมาะสมเป็นเรื่องง่ายขนาดที่ว่า การใช้งานมันคู่กับ library ปลายน้ำสามารถเสร็จได้ในการใช้โค้ดเพียงไม่กี่บรรทัดเท่านั้น มาดูวิธีใช้โมเดลพวกนี้และการให้ความช่วยเหลือกับชุมชนกันดีกว่า -Let's say we're looking for a French-based model that can perform mask filling. +สมมุติว่าเรากำลังมองหาโมเดลภาษาฝรั่งเศสที่สามารถเติมคำที่หายไปได้ (mask filling)
Selecting the Camembert model.
-We select the `camembert-base` checkpoint to try it out. The identifier `camembert-base` is all we need to start using it! As you've seen in previous chapters, we can instantiate it using the `pipeline()` function: +เราเลือก `camembert-base` checkpoint มาลองใช้ ตัวระบุ `camembert-base` คือทั้งหมดที่เราต้องการในการเริ่มใช้งาน! อย่างที่คุณได้เห็นไปแล้วในบทก่อนหน้านี้ เราสามารถเรียกใช้งานมันได้ด้วยคำสั่ง `pipeline()`: ```py from transformers import pipeline @@ -49,13 +49,13 @@ results = camembert_fill_mask("Le camembert est :)") ] ``` -As you can see, loading a model within a pipeline is extremely simple. The only thing you need to watch out for is that the chosen checkpoint is suitable for the task it's going to be used for. For example, here we are loading the `camembert-base` checkpoint in the `fill-mask` pipeline, which is completely fine. But if we were to load this checkpoint in the `text-classification` pipeline, the results would not make any sense because the head of `camembert-base` is not suitable for this task! We recommend using the task selector in the Hugging Face Hub interface in order to select the appropriate checkpoints: +อย่างที่คุณเห็น การโหลดโมเดลใน pipeline นั้นง่ายมากๆ สิ่งเดียวที่ควรระวังคือ checkpoint ที่คุณเลือกนั้นควรเหมาะสมกับประเภทของงานที่คุณจะทำ อย่างเช่น ในงานนี้เราโหลด `camembert-base` checkpoint ใน `fill-mask` pipeline ซึ่งเหมาะกับงานที่เราจะใช้อย่างแน่นอน แต่ถ้าเราโหลด checkpoint นี้ใน `text-classification` pipeline ผลลัพธ์จะไม่สมเหตุสมผล เพราะหัวข้อของ `camembert-base` ไม่เหมาะสมกับงานประเภทนี้! เราแนะนำให้ใช้ตัวเลือกประเภทงาน (task selector) ในอินเตอร์เฟซของ Hugging Face Hub เพื่อเลือก checkpoints ที่เหมาะสม
The task selector on the web interface.
-You can also instantiate the checkpoint using the model architecture directly: +คุณสามารถเรียกใช้ checkpoint โดยการใช้สถาปัตยกรรมโมเดล (model architecture) ได้โดยตรงด้วย: {#if fw === 'pt'} ```py @@ -65,7 +65,7 @@ tokenizer = CamembertTokenizer.from_pretrained("camembert-base") model = CamembertForMaskedLM.from_pretrained("camembert-base") ``` -However, we recommend using the [`Auto*` classes](https://huggingface.co/transformers/model_doc/auto.html?highlight=auto#auto-classes) instead, as these are by design architecture-agnostic. While the previous code sample limits users to checkpoints loadable in the CamemBERT architecture, using the `Auto*` classes makes switching checkpoints simple: +อย่างไรก็ตาม เราแนะนำให้ใช้ [คลาส `Auto*`](https://huggingface.co/transformers/model_doc/auto.html?highlight=auto#auto-classes) แทน เพราะว่ามันเป็นคลาสที่สามารถใช้ได้กับสถาปัตยกรรมหลายประเภท (design architecture-agnostic) ในขณะที่โค้ดก่อนหน้านี้จำกัดผู้ใช้อยู่กับ checkpoints ที่สามารถโหลดได้เฉพาะกับสถาปัตยกรรมแบบ CamemBERT การใช้คลาส `Auto*` นั้นทำให้การเปลี่ยน checkpoints เป็นเรื่องง่าย: ```py from transformers import AutoTokenizer, AutoModelForMaskedLM @@ -81,7 +81,7 @@ tokenizer = CamembertTokenizer.from_pretrained("camembert-base") model = TFCamembertForMaskedLM.from_pretrained("camembert-base") ``` -However, we recommend using the [`TFAuto*` classes](https://huggingface.co/transformers/model_doc/auto.html?highlight=auto#auto-classes) instead, as these are by design architecture-agnostic. While the previous code sample limits users to checkpoints loadable in the CamemBERT architecture, using the `TFAuto*` classes makes switching checkpoints simple: +อย่างไรก็ตาม เราแนะนำให้ใช้ [คลาส `TFAuto*`](https://huggingface.co/transformers/model_doc/auto.html?highlight=auto#auto-classes) แทน เพราะว่ามันเป็นคลาสที่สามารถใช้ได้กับสถาปัตยกรรมหลายประเภท (design architecture-agnostic) ในขณะที่โค้ดก่อนหน้านี้จำกัดผู้ใช้อยู่กับ checkpoints ที่สามารถโหลดได้เฉพาะกับสถาปัตยกรรมแบบ CamemBERT การใช้คลาส `TFAuto*` นั้นทำให้การเปลี่ยน checkpoints เป็นเรื่องง่าย: ```py from transformers import AutoTokenizer, TFAutoModelForMaskedLM @@ -92,5 +92,5 @@ model = TFAutoModelForMaskedLM.from_pretrained("camembert-base") {/if} -When using a pretrained model, make sure to check how it was trained, on which datasets, its limits, and its biases. All of this information should be indicated on its model card. +เมื่อมีการใช้งานโมเดลที่ผ่านการเทรนมาแล้ว (pretrained model) คุณควรตรวจสอบให้มั่นใจว่ามันถูกเทรนมาอย่างไร กับชุดข้อมูลไหน ขีดจำกัด (limits) และความลำเอียง (biases) คืออะไร ซึ่งข้อมูลทั้งหมดนี้ควรถูกระบุอยู่ในการ์ดโมเดล (model card) From 60a58ad45da0dc842bf9b4db1331a688fba1de50 Mon Sep 17 00:00:00 2001 From: "jomariya.son@gmail.com" Date: Sat, 2 Apr 2022 18:22:24 +0700 Subject: [PATCH 03/12] Translated chapter4/3 --- chapters/th/chapter4/3.mdx | 208 +++++++++++++++++++------------------ 1 file changed, 108 insertions(+), 100 deletions(-) diff --git a/chapters/th/chapter4/3.mdx b/chapters/th/chapter4/3.mdx index a2dbc7ee8..243e44fff 100644 --- a/chapters/th/chapter4/3.mdx +++ b/chapters/th/chapter4/3.mdx @@ -1,6 +1,6 @@ -# Sharing pretrained models +# การแบ่งปันโมเดลที่ผ่านการเทรนมาแล้ว (pretrained models) {#if fw === 'pt'} @@ -22,22 +22,22 @@ {/if} -In the steps below, we'll take a look at the easiest ways to share pretrained models to the 🤗 Hub. There are tools and utilities available that make it simple to share and update models directly on the Hub, which we will explore below. +ในขั้นตอนข้างล่างต่อไปนี้ เราจะมาดูวิธีที่ง่ายที่สุดในการแบ่งปันโมเดลที่ผ่านการเทรนมาแล้วบน 🤗 Hub มีเครื่องมือและสิ่งอำนวยความสะดวกมากมายที่ทำให้การแบ่งปันและอัพเดตโมเดลโดยตรงบน Hub เป็นเรื่องง่าย ซึ่งนั่นคือสิ่งที่เราจะมาสำรวจกันต่อจากนี้ -We encourage all users that train models to contribute by sharing them with the community — sharing models, even when trained on very specific datasets, will help others, saving them time and compute resources and providing access to useful trained artifacts. In turn, you can benefit from the work that others have done! +เราส่งเสริมให้ผู้ใช้ทุกคนที่เทรนโมเดลช่วยมีส่วนร่วมโดยการแบ่งปันโมเดลเหล่านั้นให้กับชุมชน การแบ่งปันโมเดลนั้นสามารถช่วยเหลือผู้อื่นได้ ช่วยลดเวลาและทรัพยากรในการประมวลผล และช่วยให้เข้าถึงไฟล์ผลลัพธ์จากการเทรน (artifacts) ที่เป็นประโยชน์ได้ แม้ว่าจะเป็นโมเดลที่ถูกเทรนมากับชุดข้อมูลที่เฉพาะเจาะจงมากก็ตาม ในทางเดียวกันนั้นคุณก็ได้รับประโยชน์จากงานที่คนอื่นได้ทำเช่นกัน! -There are three ways to go about creating new model repositories: +มี 3 วิธีที่สามารถใช้สร้าง model repositories ใหม่ได้: -- Using the `push_to_hub` API -- Using the `huggingface_hub` Python library -- Using the web interface +- ใช้ `push_to_hub` API +- ใช้ `huggingface_hub` Python library +- ใช้ web interface -Once you've created a repository, you can upload files to it via git and git-lfs. We'll walk you through creating model repositories and uploading files to them in the following sections. +เมื่อคุณได้สร้าง repository แล้ว คุณสามารถอัพโหลดไฟล์ต่างๆเข้าไปได้ผ่าน git และ git-lfs ในส่วนถัดไปเราจะพาคุณมาดูขั้นตอนการสร้าง model repositories และการอัพโหลดไฟล์ต่างๆเข้าไป -## Using the `push_to_hub` API +## ใช้ `push_to_hub` API {#if fw === 'pt'} @@ -49,9 +49,9 @@ Once you've created a repository, you can upload files to it via git and git-lfs {/if} -The simplest way to upload files to the Hub is by leveraging the `push_to_hub` API. +วิธีที่ง่ายที่สุดในการอัพโหลดไฟล์ขึ้นไปสู่ Hub คือการใช้ `push_to_hub` API -Before going further, you'll need to generate an authentication token so that the `huggingface_hub` API knows who you are and what namespaces you have write access to. Make sure you are in an environment where you have `transformers` installed (see [Setup](/course/chapter0)). If you are in a notebook, you can use the following function to login: +ก่อนจะไปกันต่อ คุณจะต้องสร้างโทเค็นสำหรับรับรองความน่าเชื่อถือ (authentication token) เพื่อให้ `huggingface_hub` API รู้ว่าคุณคือใครและคุณมีสิทธิ์ในการเขียน (write access) ใน namespaces อะไรบ้าง ในตอนนี้ให้คุณทำให้มั่นใจว่าคุณอยู่ใน environment ที่คุณได้ทำการติดตั้ง `transformers` เอาไว้แล้ว (ดู [ติดตั้งโปรแกรม](/course/chapter0)) ถ้าคุณกำลังอยู่ใน notebook คุณสามารถใช้งานคำสั่งต่อไปนี้ในการเข้าสู่ระบบได้เลย: ```python from huggingface_hub import notebook_login @@ -59,19 +59,19 @@ from huggingface_hub import notebook_login notebook_login() ``` -In a terminal, you can run: +สำหรับใน terminal คนสามารถรัน: ```bash huggingface-cli login ``` -In both cases, you should be prompted for your username and password, which are the same ones you use to log in to the Hub. If you do not have a Hub profile yet, you should create one [here](https://huggingface.co/join). +ในทั้งสองกรณี คุณควรจะถูกให้กรอก username และ password ซึ่งเป็นชุดเดียวกันกับที่คุณใช้ในการ login เข้าสู่ Hub ถ้าหากคุณยังไม่มีโปรไฟล์ Hub คุณสามารถสร้างได้ [ที่นี่](https://huggingface.co/join) -Great! You now have your authentication token stored in your cache folder. Let's create some repositories! +เยี่ยม! ตอนนี้คุณมี authentication token เก็บเอาไว้ใน cache folder ของคุณแล้ว มาเริ่มสร้าง repositories กันเถอะ! {#if fw === 'pt'} -If you have played around with the `Trainer` API to train a model, the easiest way to upload it to the Hub is to set `push_to_hub=True` when you define your `TrainingArguments`: +ถ้าคุณเคยได้ลองใช้งาน `Trainer` API ในการเทรนโมเดลมาบ้างแล้ว วิธีที่ง่ายที่สุดที่จะอัพโหลดขึ้นไปสู่ Hub คือการตั้ง `push_to_hub=True` ตอนที่คุณกำหนด `TrainingArguments`: ```py from transformers import TrainingArguments @@ -81,11 +81,11 @@ training_args = TrainingArguments( ) ``` -When you call `trainer.train()`, the `Trainer` will then upload your model to the Hub each time it is saved (here every epoch) in a repository in your namespace. That repository will be named like the output directory you picked (here `bert-finetuned-mrpc`) but you can choose a different name with `hub_model_id = "a_different_name"`. +เมื่อคุณเรียกใช้ `trainer.train()` ตัว `Trainer` จะทำการอัพโหลดโมเดลของคุณขึ้นสู่ Hub ในทุกๆครั้งที่มันถูกบันทึก (ในที่นี้คือ ทุกๆรอบการเทรน (epoch)) ใน repository และ namespace ของคุณ repository นั้นจะถูกตั้งชื่อให้เหมือนกับโฟลเดอร์ output ที่คุณเลือก (ในที่นี้คือ `bert-finetuned-mrpc`) แต่คุณสามารถเลือกชื่ออื่นได้โดยการใช้ `hub_model_id = "ชื่ออื่น"` -To upload you model to an organization you are a member of, just pass it with `hub_model_id = "my_organization/my_repo_name"`. +สำหรับการอัพโหลดโมเดลของคุณเข้าสู่องค์กรที่คุณเป็นสมาชิกนั้น คุณสามารถทำได้โดย เพียงแค่ผ่านตัวแปล `hub_model_id = "องค์กร_ของคุณ/ชื่อ_repo_ของคุณ"` เข้าไป -Once your training is finished, you should do a final `trainer.push_to_hub()` to upload the last version of your model. It will also generate a model card with all the relevant metadata, reporting the hyperparameters used and the evaluation results! Here is an example of the content you might find in a such a model card: +เมื่อการเทรนของคุณเสร็จสิ้น คุณควรที่จะใช้ `trainer.push_to_hub()` อีกครั้งเป็นครั้งสุดท้าย เพื่ออัพโหลดโมเดลเวอร์ชั่นล่าสุดของคุณ มันจะสร้างการ์ดโมเดล (model card) ที่มีข้อมูลเมตา (metadata) ที่เกี่ยวข้อง เช่น รายงาน hyperparameters ที่ใช้ และผลลัพธ์ของการประเมินผล (evaluation result) ให้คุณด้วย! ต่อไปนี้เป็นตัวอย่างของเนื้อหาที่คุณเจอได้ในการ์ดโมเดล:
An example of an auto-generated model card. @@ -93,7 +93,7 @@ Once your training is finished, you should do a final `trainer.push_to_hub()` to {:else} -If you are using Keras to train your model, the easiest way to upload it to the Hub is to pass along a `PushToHubCallback` when you call `model.fit()`: +ถ้าคุณใช้ Keras ในเทรนโมเดล วิธีที่ง่ายที่สุดที่จะอัพโหลดมันขึ้นสู่ Hub คือการผ่านค่าตัวแปร `PushToHubCallback` เข้าไป เมื่อคุณเรียกใช้ `model.fit()`: ```py from transformers import PushToHubCallback @@ -103,15 +103,15 @@ callback = PushToHubCallback( ) ``` -Then you should add `callbacks=[callback]` in your call to `model.fit()`. The callback will then upload your model to the Hub each time it is saved (here every epoch) in a repository in your namespace. That repository will be named like the output directory you picked (here `bert-finetuned-mrpc`) but you can choose a different name with `hub_model_id = "a_different_name"`. +ต่อจากนั้นคุณควรเพิ่ม `callbacks=[callback]` ไปในตอนที่คุณเรียก `model.fit()` ตัว callback นี้จะทำการอัพโหลดโมเดลของคุณขึ้นสู่ Hub ในทุกๆครั้งที่มันถูกบันทึก (ในที่นี้คือ ทุกๆรอบการเทรน (epoch)) ใน repository และ namespace ของคุณ repository นั้นจะถูกตั้งชื่อให้เหมือนกับโฟลเดอร์ output ที่คุณเลือก (ในที่นี้คือ `bert-finetuned-mrpc`) แต่คุณสามารถเลือกชื่ออื่นได้โดยการใช้ `hub_model_id = "ชื่ออื่น"` -To upload you model to an organization you are a member of, just pass it with `hub_model_id = "my_organization/my_repo_name"`. +สำหรับการอัพโหลดโมเดลของคุณเข้าสู่องค์กรที่คุณเป็นสมาชิกนั้น คุณสามารถทำได้โดย เพียงแค่ผ่านตัวแปล `hub_model_id = "องค์กร_ของคุณ/ชื่อ_repo_ของคุณ"` เข้าไป {/if} -At a lower level, accessing the Model Hub can be done directly on models, tokenizers, and configuration objects via their `push_to_hub()` method. This method takes care of both the repository creation and pushing the model and tokenizer files directly to the repository. No manual handling is required, unlike with the API we'll see below. +ในระดับล่างลงไปนั้น การเข้าถึง Model Hub สามารถทำได้โดยตรงจาก objects ประเภท models, tokenizers และconfiguration ผ่านคำสั่ง `push_to_hub()` คำสั่งนี้จะจัดการทั้งการสร้าง repository และการดันไฟล์โมเดลและ tokenizer ขึ้นสู่ repository โดยตรง ไม่มีความจำเป็นที่จะต้องทำอะไรด้วยตนเองเลย ไม่เหมือนกับ API ที่เราจะได้เห็นข้างล่างนี้ -To get an idea of how it works, let's first initialize a model and a tokenizer: +เพื่อให้เห็นภาพมากขึ้นว่ามันทำงานอย่างไร เรามาเริ่มสร้างโมเดลและ tokenizer ตัวแรกกันเถอะ: {#if fw === 'pt'} ```py @@ -133,34 +133,35 @@ tokenizer = AutoTokenizer.from_pretrained(checkpoint) ``` {/if} -You're free to do whatever you want with these — add tokens to the tokenizer, train the model, fine-tune it. Once you're happy with the resulting model, weights, and tokenizer, you can leverage the `push_to_hub()` method directly available on the `model` object: +ถึงจุดนี้คุณสามารถทำอะไรก็ได้กับมันตามที่คุณต้องการ ไม่ว่าจะเป็นการเพิ่ม tokens ไปใน tokenizer, การเทรนโมเดล, การ fine-tune โมเดล หลังจากที่คุณพอใจกับผลลัพธ์ของโมเดล, weights และ tokenizer แล้ว คุณสามารถเรียกใช้คำสั่ง `push_to_hub()` ที่มีอยู่ในตัว `model` object ได้โดยตรง ```py model.push_to_hub("dummy-model") ``` -This will create the new repository `dummy-model` in your profile, and populate it with your model files. -Do the same with the tokenizer, so that all the files are now available in this repository: +ขั้นตอนนี้จะสร้าง repository ใหม่ชื่อ `dummy-model` ในโปรไฟล์ของคุณ และเติมมันด้วยไฟล์โมเดลต่างๆของคุณ +ทำแบบเดียวกันนี้กับ tokenizer นั่นจะทำให้ไฟล์ทั้งหมดอยู่บน repository นี้: ```py tokenizer.push_to_hub("dummy-model") ``` If you belong to an organization, simply specify the `organization` argument to upload to that organization's namespace: +ถ้าคุณสังกัดองค์กร คุณสามารถระบุชื่อขององค์กรใน `organization` argument เพื่ออัพโหลดเข้าไปใน namespace ขององค์กร: ```py tokenizer.push_to_hub("dummy-model", organization="huggingface") ``` -If you wish to use a specific Hugging Face token, you're free to specify it to the `push_to_hub()` method as well: +ถ้าคุณต้องการที่จะใช้งานโทเค็นของ Hugging Face โดยเฉพาะเจาะจง คุณสามารถระบุมันไปในคำสั่ง `push_to_hub()` ได้เช่นกัน: ```py tokenizer.push_to_hub("dummy-model", organization="huggingface", use_auth_token="") ``` -Now head to the Model Hub to find your newly uploaded model: *https://huggingface.co/user-or-organization/dummy-model*. +ในตอนนี้ให้คุณมุ่งหน้าไปที่ Model Hub เพื่อหาโมเดลที่คุณเพิ่งได้อัพโหลดไป: *https://huggingface.co/ชื่อ-user-หรือ-organization/dummy-model* -Click on the "Files and versions" tab, and you should see the files visible in the following screenshot: +คลิกไปที่แท็บ "Files and versions" และคุณควรจะเห็นไฟล์แบบในภาพข้างล่างนี้: {#if fw === 'pt'}
@@ -174,29 +175,33 @@ Click on the "Files and versions" tab, and you should see the files visible in t -✏️ **Try it out!** Take the model and tokenizer associated with the `bert-base-cased` checkpoint and upload them to a repo in your namespace using the `push_to_hub()` method. Double-check that the repo appears properly on your page before deleting it. +✏️ **ทดลองใช้ได้เลย! ** นำโมเดลและ tokenizer ที่เกี่ยวข้องกับ `bert-base-cased` checkpoint และอัพโหลดขึ้นไปบน repo ใน namespace ของคุณด้วยคำสั่ง `push_to_hub()` จากนั้นลองตรวจสอบดูว่า repo ปรากฏออกมาในรูปแบบที่สมควรจะเป็นบนหน้าของคุณ ก่อนที่จะลบมันออกไป -As you've seen, the `push_to_hub()` method accepts several arguments, making it possible to upload to a specific repository or organization namespace, or to use a different API token. We recommend you take a look at the method specification available directly in the [🤗 Transformers documentation](https://huggingface.co/transformers/model_sharing.html) to get an idea of what is possible. +อย่างที่คุณได้เห็น คำสั่ง `push_to_hub()` สามารถรับ arguments ได้มากมาย ทำให้สามารถอัพไฟล์ไปยัง repository หรือ namespace ขององค์กรแบบเจาะจง หรือใช้งานโทเค็น API ที่ต่างกันได้ เราแนะนำให้คุณลองเปิดดูรายละเอียดของคำสั่งนี้ได้โดยตรงที่ [🤗 Transformers documentation](https://huggingface.co/transformers/model_sharing.html) เพื่อจะได้เข้าใจมากขึ้นว่าคำสั่งนี้สามารถทำอะไรได้บ้าง -The `push_to_hub()` method is backed by the [`huggingface_hub`](https://github.com/huggingface/huggingface_hub) Python package, which offers a direct API to the Hugging Face Hub. It's integrated within 🤗 Transformers and several other machine learning libraries, like [`allenlp`](https://github.com/allenai/allennlp). Although we focus on the 🤗 Transformers integration in this chapter, integrating it into your own code or library is simple. +คำสั่ง `push_to_hub()` ได้รับการหนุนหลังโดย [`huggingface_hub`](https://github.com/huggingface/huggingface_hub) Python package ซึ่งให้ API โดยตรงไปสู่ Hugging Face Hub มันถูกบูรณาการเข้ากับ 🤗 Transformers และ machine learning libraries อื่นๆอีกหลายอันด้วย เช่น [`allenlp`](https://github.com/allenai/allennlp) แม้ว่าเราเจาะจงแค่การบูรณาการกับ 🤗 Transformers ในบทนี้ แต่การบูรณาการกับการใช้โค้ดของคุณเองหรือ library อื่นนั้นเรียบง่ายมาก -Jump to the last section to see how to upload files to your newly created repository! +ข้ามไปส่วนสุดท้ายเพื่อดูวิธีการอัพโหลดไฟล์ขึ้นไปบน repository ที่คุณสร้างขึ้นมาใหม่! -## Using the `huggingface_hub` Python library +## ใช้ `huggingface_hub` Python library The `huggingface_hub` Python library is a package which offers a set of tools for the model and datasets hubs. It provides simple methods and classes for common tasks like getting information about repositories on the hub and managing them. It provides simple APIs that work on top of git to manage those repositories' content and to integrate the Hub in your projects and libraries. -Similarly to using the `push_to_hub` API, this will require you to have your API token saved in your cache. In order to do this, you will need to use the `login` command from the CLI, as mentioned in the previous section (again, make sure to prepend these commands with the `!` character if running in Google Colab): +`huggingface_hub` Python library คือ package หนึ่งที่บรรจุชุดเครื่องมือสำหรับ hub ของโมเดลและชุดข้อมูล มันมีคำสั่งและคลาสที่เรียบง่ายไว้สำหรับงานทั่วไปอย่าง +การดึงข้อมูลเกี่ยวกับ repositories บน hub และการจัดการมัน มันมี API ง่ายๆที่สามารถทำงานบน git เพื่อที่จะจัดการเนื้อหาของ repositories เหล่านั้นและบูรณาการเข้ากับ Hub +ในงานโปรเจคและ libraries ของคุณ + +คล้ายคลึงกับการใช้ `push_to_hub` API คุณจำเป็นจะต้องมีโทเค็น API เก็บไว้ใน cache ของคุณ เพื่อที่จะมีมันได้ คุณจะต้องใช้คำสั่ง `login` จาก CLI อย่างที่เราเคยกล่าวถึงไปแล้วในส่วนก่อนหน้านี้ (ย้ำอีกครั้ง ทำให้มั่นใจว่าคุณใส่เครื่องหมาย `!` ไว้ข้างหน้าคำสั่งถ้าคุณกำลังรันใน Google Colab): ```bash huggingface-cli login ``` -The `huggingface_hub` package offers several methods and classes which are useful for our purpose. Firstly, there are a few methods to manage repository creation, deletion, and others: +`huggingface_hub` package บรรจุคำสั่งและคลาสซึ่งเป็นประโยชน์สำหรับจุดประสงค์ของเราเอาไว้หลายอย่าง อย่างแรก มีคำสั่งจำนวนหนึ่งที่ใช้จัดการกับการสร้าง, การลบ และการจัดการอื่นๆของ repository ```python no-format from huggingface_hub import ( @@ -221,9 +226,9 @@ from huggingface_hub import ( ``` -Additionally, it offers the very powerful `Repository` class to manage a local repository. We will explore these methods and that class in the next few section to understand how to leverage them. +มากไปกว่านั้น มันยังมี `Repository` class ที่ทรงพลังมากๆไว้จัดการกับ local repository เราจะมาสำรวจคำสั่งเหล่านี้และคลาสนั้นกันในอีกส่วนไม่ไกลข้างหน้า เพื่อที่จะได้เข้าใจวิธีการนำมันมาใช้ -The `create_repo` method can be used to create a new repository on the hub: +คำสั่ง `create_repo` สามารถใช้ในการสร้าง repository ใหม่บน hub ได้ ```py from huggingface_hub import create_repo @@ -231,7 +236,7 @@ from huggingface_hub import create_repo create_repo("dummy-model") ``` -This will create the repository `dummy-model` in your namespace. If you like, you can specify which organization the repository should belong to using the `organization` argument: +โค้ดนี้จะสร้าง repository ชื่อ `dummy-model` ใน namespace ของคุณ ถ้าคนชอบ คุณสามารถระบุอย่างเจาะจงไปได้ว่า repository นี้เป็นขององค์กรไหน โดยการใช้ `organization` argument: ```py from huggingface_hub import create_repo @@ -239,64 +244,64 @@ from huggingface_hub import create_repo create_repo("dummy-model", organization="huggingface") ``` -This will create the `dummy-model` repository in the `huggingface` namespace, assuming you belong to that organization. -Other arguments which may be useful are: +โค้ดนี้จะสร้าง repository ชื่อ `dummy-model` ใน namespace ของ `huggingface` สมมุติว่าคุณเป็นคนขององค์กรนั้น +Arguments อื่นที่อาจจะเป็นประโยชน์: -- `private`, in order to specify if the repository should be visible from others or not. -- `token`, if you would like to override the token stored in your cache by a given token. -- `repo_type`, if you would like to create a `dataset` or a `space` instead of a model. Accepted values are `"dataset"` and `"space"`. +- `private` ใช้ในการระบุว่าคนอื่นควรเห็น repository นี้ได้หรือไม่ +- `token` ใช้ในกรณีที่คุณอยากจะแทนที่โทเค็นที่ถูกเก็บเอาไว้ใน cache ของคุณด้วยอีกโทเค็นที่ให้ไว้ +- `repo_type` ใช้ในกรณีที่คุณอยากจะสร้าง `dataset` หรือ `space` แทนที่จะเป็นโมเดล ค่าที่รับได้คือ `"dataset"` และ `"space"` -Once the repository is created, we should add files to it! Jump to the next section to see the three ways this can be handled. +เมื่อ repository ถูกสร้างขึ้นมาแล้ว เราสามารถเพิ่มไฟล์ไปในนั้นได้! ข้ามไปส่วนถัดไปเพื่อดูสามวิธีในการทำสิ่งนี้ -## Using the web interface +## ใช้ web interface -The web interface offers tools to manage repositories directly in the Hub. Using the interface, you can easily create repositories, add files (even large ones!), explore models, visualize diffs, and much more. +web interface บรรจุเครื่องมือมากมายที่ใช้จัดการ repositories โดยตรงใน Hub ด้วยการใช้งาน web interface คุณสามารถสร้าง repositories, เพิ่มไฟล์ (รวมถึงไฟล์ขนาดใหญ่ด้วย!), สำรวจโมเดลต่างๆ, แสดงผลความแตกต่าง และอื่นๆอีกมากมายได้อย่างง่ายดาย -To create a new repository, visit [huggingface.co/new](https://huggingface.co/new): +สร้าง repository ใหม่ได้โดยการไปที่ [huggingface.co/new](https://huggingface.co/new):
Page showcasing the model used for the creation of a new model repository.
-First, specify the owner of the repository: this can be either you or any of the organizations you're affiliated with. If you choose an organization, the model will be featured on the organization's page and every member of the organization will have the ability to contribute to the repository. +ขั้นแรก ระบุเจ้าของของ repository ซึ่งสามารถเป็นคุณเองหรือองค์กรใดๆที่คุณเกี่ยวข้องด้วย ถ้าคุณเลือกองค์กร โมเดลจะถูกนำไปขึ้นบนหน้าขององค์กรด้วย และสมาชิกทุกคนขององค์กรนั้นจะมีสิทธิ์ในการมีส่วนร่วมกับ repository นี้ -Next, enter your model's name. This will also be the name of the repository. Finally, you can specify whether you want your model to be public or private. Private models are hidden from public view. +ถัดไป ใส่ชื่อโมเดลของคุณ ซึ่งจะเหมือนกับชื่อของ repository ก็ได้ และสุดท้าย คุณสามารถระบุได้ว่าคุณต้องการให้โมเดลของคุณเป็นสาธารณะหรือส่วนบุคคล โมเดลส่วนบุคคลนั้นจะถูกซ่อนจากมุมมองสาธารณะ -After creating your model repository, you should see a page like this: +หลังจากที่คุณสร้าง model repository ของคุณแล้ว คุณควรจะเห็นหน้าแบบนี้:
An empty model page after creating a new repository.
-This is where your model will be hosted. To start populating it, you can add a README file directly from the web interface. +นี่คือที่ที่โมเดลของคุณจะถูก host เอาไว้ สำหรับการเริ่มปรับแต่งเพิ่มเติมนั้น คุณสามารถเพิ่มไฟล์ README ได้โดยตรงจาก web interface
The README file showing the Markdown capabilities.
-The README file is in Markdown — feel free to go wild with it! The third part of this chapter is dedicated to building a model card. These are of prime importance in bringing value to your model, as they're where you tell others what it can do. +ไฟล์ README อยู่ในรูปแบบของ Markdown — สามารถปรับแต่งมันแบบจัดเต็มได้เลย! ในส่วนที่สามของบทนี้ถูกอุทิศให้กับการสร้างการ์ดโมเดล (model card) ซึ่งนี่เป็นส่วนที่สำคัญเป็นอันดับหนึ่งในการสร้างคุณค่าให้โมเดลของคุณ เพราะว่ามันจะเป็นสิ่งที่ใช้บอกคนอื่นว่าโมเดลของคุณทำอะไรได้บ้าง -If you look at the "Files and versions" tab, you'll see that there aren't many files there yet — just the *README.md* you just created and the *.gitattributes* file that keeps track of large files. +ถ้าคุณดูที่แท็บ "Files and versions" คุณจะเห็นว่ามันยังไม่มีไฟล์อะไรมากมายเลย — แค่ไฟล์ *README.md* ที่คุณเพิ่งได้สร้างและไฟล์ *.gitattributes* สำหรับไว้ติดตามไฟล์ขนาดใหญ่
The 'Files and versions' tab only shows the .gitattributes and README.md files.
-We'll take a look at how to add some new files next. +ต่อไปเราจะมาดูวิธีการเพิ่มไฟล์ใหม่กัน -## Uploading the model files +## การอัพโหลดไฟล์โมเดลต่างๆ -The system to manage files on the Hugging Face Hub is based on git for regular files, and git-lfs (which stands for [Git Large File Storage](https://git-lfs.github.com/)) for larger files. +ระบบที่ใช้จัดการไฟล์บน Hugging Face Hub มีพื้นฐานมาจาก git สำหรับไฟล์ทั่วไป และ git-lfs (ย่อมาจาก [Git Large File Storage](https://git-lfs.github.com/)) สำหรับไฟล์ที่ใหญ่ขึ้น -In the next section, we go over three different ways of uploading files to the Hub: through `huggingface_hub` and through git commands. +ในส่วนถัดไปนี้ เราจะพามาดูสามวิธีในการอัพโหลดไฟล์ต่างๆไปบน Hub: ผ่าน `huggingface_hub` และ ผ่านคำสั่ง git ต่างๆ -### The `upload_file` approach +### แนวทางแบบใช้ `upload_file` -Using `upload_file` does not require git and git-lfs to be installed on your system. It pushes files directly to the 🤗 Hub using HTTP POST requests. A limitation of this approach is that it doesn't handle files that are larger than 5GB in size. -If your files are larger than 5GB, please follow the two other methods detailed below. +การใช้ `upload_file` ไม่จำเป็นต้องมี git และ git-lfs ติดตั้งอยู่บนระบบของคุณ มันดันไฟล์โดยตรงไปสู่ 🤗 Hub โดยใช้ HTTP POST requests ข้อจำกัดของแนวทางนี้คือมันไม่สามารถรองรับไฟล์ที่มีขนาดมากกว่า 5GB ได้ +ถ้าไฟล์ของคุณมีขนาดใหญ่กว่า 5GB โปรดทำตามอีกสองขั้นตอนที่ระบุรายละเอียดไว้ด้านล่าง -The API may be used as follows: +API สามารถถูกใช้แบบนี้ได้: ```py from huggingface_hub import upload_file @@ -308,20 +313,20 @@ upload_file( ) ``` -This will upload the file `config.json` available at `` to the root of the repository as `config.json`, to the `dummy-model` repository. -Other arguments which may be useful are: +โค้ดนี้จะทำการอัพโหลดไฟล์ `config.json` ที่อยู่ใน `` ไปสู่รากของ repository โดยใช้ชื่อ `config.json` ไปสู่ `dummy-model` repository +Arguments อื่นที่อาจจะเป็นประโยชน์: -- `token`, if you would like to override the token stored in your cache by a given token. -- `repo_type`, if you would like to upload to a `dataset` or a `space` instead of a model. Accepted values are `"dataset"` and `"space"`. +- `token` ใช้ในกรณีที่คุณอยากจะแทนที่โทเค็นที่ถูกเก็บเอาไว้ใน cache ของคุณด้วยอีกโทเค็นที่ให้ไว้ +- `repo_type` ใช้ในกรณีที่คุณอยากจะสร้าง `dataset` หรือ `space` แทนที่จะเป็นโมเดล ค่าที่รับได้คือ `"dataset"` และ `"space"` -### The `Repository` class +### คลาส `Repository` -The `Repository` class manages a local repository in a git-like manner. It abstracts most of the pain points one may have with git to provide all features that we require. +คลาส `Repository` จัดการ local repository ในลักษณะคล้าย git มันเอาปัญหาส่วนมากที่ผู้คนมักเจอเวลาใช้ git ออกเพื่อจัดสรรทุกฟีเจอร์ทุกอย่างที่เราจำเป็นต้องใช้ -Using this class requires having git and git-lfs installed, so make sure you have git-lfs installed (see [here](https://git-lfs.github.com/) for installation instructions) and set up before you begin. +การใช้คลาสนี้จำเป็นต้องติดตั้ง git และ git-lfs ดังนั้นคุณควรทำให้มั่นใจว่าคุณได้ติดตั้ง git-lfs แล้ว (ดู [ที่นี่](https://git-lfs.github.com/) สำหรับขั้นตอนการติดตั้ง) และตั้งค่าให้เสร็จก่อนที่คุณจะเริ่มไปต่อ -In order to start playing around with the repository we have just created, we can start by initialising it into a local folder by cloning the remote repository: +เพื่อที่จะเริ่มเล่นกับ repository ที่เราเพิ่งจะได้สร้างกัน เราสามารถเริ่มตั้งต้นมันไปใน local folder ได้โดยการโคลน (clone) remote repository: ```py from huggingface_hub import Repository @@ -329,9 +334,9 @@ from huggingface_hub import Repository repo = Repository("", clone_from="/dummy-model") ``` -This created the folder `` in our working directory. This folder only contains the `.gitattributes` file as that's the only file created when instantiating the repository through `create_repo`. +โค้ดนี้จะสร้างโฟลเดอร์ `` ในไดเรกทอรีที่คุณทำงานอยู่ (working directory) โฟลเดอร์นี้เก็บไฟล์ `.gitattributes` เอาไว้เพียงไฟล์เดียวเพราะว่ามันเป็นไฟล์เดียวที่จะถูกสร้างเมื่อมีการสร้าง repository ตั้งต้นด้วยคำสั่ง `create_repo` -From this point on, we may leverage several of the traditional git methods: +จากจุดนี้เป็นต้นไป เราสามารถใช้คำสั่ง git แบบดั่งเดิมต่างๆได้: ```py repo.git_pull() @@ -341,24 +346,25 @@ repo.git_push() repo.git_tag() ``` -And others! We recommend taking a look at the `Repository` documentation available [here](https://github.com/huggingface/huggingface_hub/tree/main/src/huggingface_hub#advanced-programmatic-repository-management) for an overview of all available methods. +และอื่นๆอีก! เราแนะนำให้ลองไปดูที่หนังสืออ้างอิง (documentation) ของ `Repository` ซึ่งเข้าถึงได้จาก [ที่นี่](https://github.com/huggingface/huggingface_hub/tree/main/src/huggingface_hub#advanced-programmatic-repository-management) สำหรับภาพรวมของคำสั่งทั้งหมดที่ใช้ได้ -At present, we have a model and a tokenizer that we would like to push to the hub. We have successfully cloned the repository, we can therefore save the files within that repository. +ณ ปัจจุบัน เรามีโมเดลและ tokenizer ซึ่งเราต้องการที่จะดันขึ้นสู่ hub แล้ว เราได้โคลน repository มาอย่างเสร็จสมบูรณ์ ดังนั้นเราสามารถเก็บไฟล์ต่างๆไว้ใน repository นั้นได้แล้ว -We first make sure that our local clone is up to date by pulling the latest changes: +อันดับแรกเราต้องทำให้มั่นใจว่า local clone ของเรานั้นเป็นปัจจุบัน ซึ่งทำได้โดยการดึง (pull) การเปลี่ยนแปลงใหม่ล่าสุดเข้ามา: ```py repo.git_pull() ``` Once that is done, we save the model and tokenizer files: +เมื่อโค้ดทำงานเสร็จแล้ว เราเก็บไฟล์โมเดลและ tokenizer: ```py model.save_pretrained("") tokenizer.save_pretrained("") ``` -The `` now contains all the model and tokenizer files. We follow the usual git workflow by adding files to the staging area, committing them and pushing them to the hub: +ที่ `` ตอนนี้มีไฟล์โมเดลและ tokenizer ทั้งหมดแล้ว เราจะทำตาม workflow ของ git ทั่วไปโดยการ เพิ่มไฟล์ไปยัง staging area, ทำการ commit และดัน (push) ไฟล์เหล่านั้นสู่ hub: ```py repo.git_add() @@ -366,15 +372,15 @@ repo.git_commit("Add model and tokenizer files") repo.git_push() ``` -Congratulations! You just pushed your first files on the hub. +ขอแสดงความยินดีด้วย! คุณเพิ่งได้ทำการดันไฟล์ชุดแรกของคุณสู่ hub -### The git-based approach +### แนวทางแบบใช้ git -This is the very barebones approach to uploading files: we'll do so with git and git-lfs directly. Most of the difficulty is abstracted away by previous approaches, but there are a few caveats with the following method so we'll follow a more complex use-case. +แนวทางนี้เป็นแนวทางที่ตรงๆมากสำหรับทำการอัพโหลดไฟล์ นั่นคือเราจะใช้ git และ git-lfs โดยตรง ส่วนที่ยากส่วนใหญ่ถูกในออกไปในแนวทางก่อนๆ แต่มันมีข้อแม้บางอย่างกับขั้นตอนแต่ไปนี้ ดังนั้นเราจะทำตามการใช้งานแบบที่ซับซ้อนขึ้นกว่าปกติ -Using this class requires having git and git-lfs installed, so make sure you have [git-lfs](https://git-lfs.github.com/) installed (see here for installation instructions) and set up before you begin. +การใช้งานต่อจากนี้จำเป็นต้องติดตั้ง git และ git-lfs ดังนั้นคุณควรทำให้มั่นใจว่าคุณได้ติดตั้ง git-lfs แล้ว (ดู [ที่นี่](https://git-lfs.github.com/) สำหรับขั้นตอนการติดตั้ง) และตั้งค่าให้เสร็จก่อนที่คุณจะเริ่มไปต่อ -First start by initializing git-lfs: +เริ่มแรกโดยการเริ่มต้นสร้าง git-lfs: ```bash git lfs install @@ -385,19 +391,20 @@ Updated git hooks. Git LFS initialized. ``` -Once that's done, the first step is to clone your model repository: +เมื่อโค้ดทำงานเสร็จแล้ว ขั้นตอนแรกคือการโคลน model repository ของคุณ: ```bash git clone https://huggingface.co// ``` -My username is `lysandre` and I've used the model name `dummy`, so for me the command ends up looking like the following: +username ของฉันคือ `lysandre` และฉันใช้ `dummy` เป็นชื่อโมเดล ดังนั้นสำหรับฉันแล้ว คำสั่งจะมีหน้าตาประมาณแบบนี้: ``` git clone https://huggingface.co/lysandre/dummy ``` I now have a folder named *dummy* in my working directory. I can `cd` into the folder and have a look at the contents: +ตอนนี้ฉันมีโฟลเดอร์ชื่อ *dummy* ในไดเรกทอรีที่ฉันทำงานอยู่ (working directory) ฉันสามารถ `cd` เข้าไปในโฟลเดอร์และดูว่ามีอะไรข้างในบ้าง: ```bash cd dummy && ls @@ -407,11 +414,11 @@ cd dummy && ls README.md ``` -If you just created your repository using Hugging Face Hub's `create_repo` method, this folder should only contain a hidden `.gitattributes` file. If you followed the instructions in the previous section to create a repository using the web interface, the folder should contain a single *README.md* file alongside the hidden `.gitattributes` file, as shown here. +ถ้าคุณสร้าง repository ด้วยการใช้คำสั่ง `create_repo` ของ Hugging Face Hub โฟลเดอร์นี้ควรจะมีไฟล์ `.gitattributes` ถูกซ่อนอยู่ด้วย ถ้าคุณทำตามขั้นตอนในส่วนก่อนหน้านี้ในการสร้าง repository โดยใช้ web interface ในโฟลเดอร์นี้ควรจะมี *README.md* หนึ่งไฟล์มาพร้อมกับไฟล์ `.gitattributes` ที่ถูกซ่อนอยู่ อย่างที่แสดงให้เห็นนี้ -Adding a regular-sized file, such as a configuration file, a vocabulary file, or basically any file under a few megabytes, is done exactly as one would do it in any git-based system. However, bigger files must be registered through git-lfs in order to push them to *huggingface.co*. +การเพิ่มไฟล์หนึ่งไฟล์ที่มีขนาดปกติ เช่น ไฟล์สำหรับกำหนดค่า (configuration file), ไฟล์สำหรับเก็บคำศัพท์ (vocabulary file) หรือโดยง่ายๆแล้วไฟล์อะไรก็ตามที่มีขนาดน้อยกว่าสองสาม megabytes สามารถทำได้ด้วยการทำแบบที่ทำปกติกับระบบที่พึ่งพา git อย่างไรก็ตามไฟล์ที่ใหญ่กว่านั้นจะต้องถูกลงทะเบียนผ่าน git-lfs เพื่อที่จะดันไฟล์เหล่านั้นขึ้นสู่ *huggingface.co* ได้ -Let's go back to Python for a bit to generate a model and tokenizer that we'd like to commit to our dummy repository: +กลับไปหา Python กันสักหน่อยเพื่อจะสร้างโมเดลและ tokenizer ที่เราต้องการจะ commit ไปสู่ repository จำลองของเรา {#if fw === 'pt'} ```py @@ -443,7 +450,7 @@ tokenizer.save_pretrained("") ``` {/if} -Now that we've saved some model and tokenizer artifacts, let's take another look at the *dummy* folder: +ถึงตอนนี้เราได้ทำการบันทึกไฟล์จากโมเดลและ tokenizer บางส่วนแล้ว ลองไปดูโฟลเดอร์ *dummy* อีกรอบกันเถอะ: ```bash ls @@ -454,28 +461,28 @@ ls config.json pytorch_model.bin README.md sentencepiece.bpe.model special_tokens_map.json tokenizer_config.json tokenizer.json ``` -If you look at the file sizes (for example, with `ls -lh`), you should see that the model state dict file (*pytorch_model.bin*) is the only outlier, at more than 400 MB. +ถ้าคุณดูที่ขนาดของไฟล์ (อย่างเช่น ใช้คำสั่ง `ls -lh`) คุณควรจะเห็นได้ว่าไฟล์ model state dict (*pytorch_model.bin*) มีขนาดที่โดดมาก นั่นคือมากกว่า 400 MB {:else} ```bash config.json README.md sentencepiece.bpe.model special_tokens_map.json tf_model.h5 tokenizer_config.json tokenizer.json ``` -If you look at the file sizes (for example, with `ls -lh`), you should see that the model state dict file (*t5_model.h5*) is the only outlier, at more than 400 MB. +ถ้าคุณดูที่ขนาดของไฟล์ (อย่างเช่น ใช้คำสั่ง `ls -lh`) คุณควรจะเห็นได้ว่าไฟล์ model state dict (*t5_model.h5*) มีขนาดที่โดดมาก นั่นคือมากกว่า 400 MB {/if} -✏️ When creating the repository from the web interface, the *.gitattributes* file is automatically set up to consider files with certain extensions, such as *.bin* and *.h5*, as large files, and git-lfs will track them with no necessary setup on your side. +✏️ ตอนที่สร้าง repository จาก web interface ไฟล์ *.gitattributes* ถูกตั้งค่าอย่างอัตโนมัติเพื่อให้พิจารณาไฟล์บางประเภท เช่น *.bin* และ *.h5* ว่าเป็นไฟล์ขนาดใหญ่ และ git-lfs จะติดตามไฟล์เหล่านั้นโดยคุณไม่จำเป็นต้องตั้งค่าอะไรเลย -We can now go ahead and proceed like we would usually do with traditional Git repositories. We can add all the files to Git's staging environment using the `git add` command: +ต่อไปเราจะทำต่อโดยการทำแบบที่เราทำกับ Git repositories ดั้งเดิม เราสามารถเพิ่มไฟล์ทั้งหมดไปยัง staging environment ของ Git ได้ด้วยการใช้คำสั่ง `git add`: ```bash git add . ``` -We can then have a look at the files that are currently staged: +เราสามารถดูได้ว่าไฟล์ที่อยู่ในสถานะ staged มีอะไรบ้าง: ```bash git status @@ -513,7 +520,7 @@ Changes to be committed: ``` {/if} -Similarly, we can make sure that git-lfs is tracking the correct files by using its `status` command: +ในแบบเดียวกัน เราสามารถทำให้มั่นใจได้ว่า git-lfs กำลังติดตามไฟล์ที่ถูกต้องอยู่ ได้โดยการใช้คำสั่ง status: ```bash git lfs status @@ -539,7 +546,7 @@ Objects not staged for commit: ``` -We can see that all files have `Git` as a handler, except *pytorch_model.bin* and *sentencepiece.bpe.model*, which have `LFS`. Great! +เราสามารถเห็นได้ว่าทุกไฟล์มี `Git` เป็นตัวจัดการ (handler) ยกเว้น *pytorch_model.bin* และ *sentencepiece.bpe.model* ซึ่งเป็น `LFS` เยี่ยม! {:else} ```bash @@ -561,11 +568,11 @@ Objects not staged for commit: ``` -We can see that all files have `Git` as a handler, except *t5_model.h5*, which has `LFS`. Great! +เราสามารถเห็นได้ว่าทุกไฟล์มี `Git` เป็นตัวจัดการ (handler) ยกเว้น *t5_model.h5* ซึ่งเป็น `LFS` เยี่ยม! {/if} -Let's proceed to the final steps, committing and pushing to the *huggingface.co* remote repository: +มาทำขั้นตอนสุดท้ายต่อกันเถอะ ทำการ commit และดัน (push) ขึ้นสู่ *huggingface.co* remote repository: ```bash git commit -m "First model version" @@ -597,6 +604,7 @@ git commit -m "First model version" {/if} Pushing can take a bit of time, depending on the speed of your internet connection and the size of your files: +การดันไฟล์นั้นอาจจะใช้เวลาสักหน่อย ขึ้นอยู่กับความเร็วของการเชื่อมต่ออินเทอร์เน็ตและขนาดไฟล์ของคุณ: ```bash git push @@ -615,25 +623,25 @@ To https://huggingface.co/lysandre/dummy ``` {#if fw === 'pt'} -If we take a look at the model repository when this is finished, we can see all the recently added files: +ถ้าเราดูที่ model repository เมื่อโค้ดทำงานเสร็จแล้ว เราจะเห็นทุกไฟล์ที่เพิ่งถูกเพิ่มเข้าไปอยู่ในนั้น:
The 'Files and versions' tab now contains all the recently uploaded files.
-The UI allows you to explore the model files and commits and to see the diff introduced by each commit: +UI ช่วยให้คุณสามารถสำรวจไฟล์โมเดลและ commits และดูความแตกต่างของแต่ละ commit ได้:
The diff introduced by the recent commit.
{:else} -If we take a look at the model repository when this is finished, we can see all the recently added files: +ถ้าเราดูที่ model repository เมื่อโค้ดทำงานเสร็จแล้ว เราจะเห็นทุกไฟล์ที่เพิ่งถูกเพิ่มเข้าไปอยู่ในนั้น:
The 'Files and versions' tab now contains all the recently uploaded files.
-The UI allows you to explore the model files and commits and to see the diff introduced by each commit: +UI ช่วยให้คุณสามารถสำรวจไฟล์โมเดลและ commits และดูความแตกต่างของแต่ละ commit ได้:
The diff introduced by the recent commit. From 204b036a466b4d1b8489ee62bec0dd2849ee1a7e Mon Sep 17 00:00:00 2001 From: "jomariya.son@gmail.com" Date: Sat, 2 Apr 2022 18:28:49 +0700 Subject: [PATCH 04/12] Revised some typos --- chapters/th/chapter4/1.mdx | 2 +- chapters/th/chapter4/3.mdx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/chapters/th/chapter4/1.mdx b/chapters/th/chapter4/1.mdx index 8f9948fe2..3078aba53 100644 --- a/chapters/th/chapter4/1.mdx +++ b/chapters/th/chapter4/1.mdx @@ -2,7 +2,7 @@ [Hugging Face Hub](https://huggingface.co/) –- เว็บไซต์หลักของเรา –- เป็นแพลตฟอร์มกลางที่ทุกคนสามารถค้นหาโมเดลและชุดข้อมูลที่ล้ำสมัยที่สุด (state-of-the-art) และสามารถนำไปใช้งาน รวมถึงมีส่วนร่วมได้ เรามีโมเดลที่เปิดให้ใช้ได้อย่างเป็นสาธารณะที่หลากหลายมากกว่า 10,000 โมเดลให้เลือกใช้ ซึ่งในบทนี้เราจะมาเจาะลึกลงในเรื่องของโมเดล และเราจะพูดถึงชุดข้อมูลในบทที่ 5 -โมเดลใน hub ของเราไม่ได้มีแค่ 🤗 Transformers หรือ NLP เท่านั้น ยังมีโมเดลจาก [Flair](https://github.com/flairNLP/flair) และ [AllenNLP](https://github.com/allenai/allennlp) สำหรับงาน NLP [Asteroid](https://github.com/asteroid-team/asteroid) และ [pyannote](https://github.com/pyannote/pyannote-audio) สำหรับงานเสียง และ [timm](https://github.com/rwightman/pytorch-image-models) สำหรับงานภาพ และอื่นๆอีกมากมาย +โมเดลใน hub ของเราไม่ได้มีแค่ 🤗 Transformers หรือ NLP เท่านั้น ยังมีโมเดลจาก [Flair](https://github.com/flairNLP/flair) และ [AllenNLP](https://github.com/allenai/allennlp) สำหรับงาน NLP, [Asteroid](https://github.com/asteroid-team/asteroid) และ [pyannote](https://github.com/pyannote/pyannote-audio) สำหรับงานเสียง และ [timm](https://github.com/rwightman/pytorch-image-models) สำหรับงานภาพ และอื่นๆอีกมากมาย โมเดลเหล่านี้ถูกเก็บไว้ในรูปแบบของ Git repository ซึ่งนั่นสามารถทำให้เกิดการกำหนดเวอร์ชั่น (versioning) และการทำซ้ำได้ (reproducibility) การแบ่งปันโมเดลบน hub นั้นหมายถึงการปล่อยโมเดลสู่ชุมชน และทำให้ผู้คนสามารถเข้าถึงโมเดลได้อย่างง่ายดาย รวมถึงช่วยกำจัดความจำเป็นในการเทรนโมเดลด้วยตัวเอง และทำให้สามารถแบ่งปันและใช้งานได้ง่ายอีกด้วย diff --git a/chapters/th/chapter4/3.mdx b/chapters/th/chapter4/3.mdx index 243e44fff..5abf0c3d9 100644 --- a/chapters/th/chapter4/3.mdx +++ b/chapters/th/chapter4/3.mdx @@ -175,7 +175,7 @@ tokenizer.push_to_hub("dummy-model", organization="huggingface", use_auth_token= -✏️ **ทดลองใช้ได้เลย! ** นำโมเดลและ tokenizer ที่เกี่ยวข้องกับ `bert-base-cased` checkpoint และอัพโหลดขึ้นไปบน repo ใน namespace ของคุณด้วยคำสั่ง `push_to_hub()` จากนั้นลองตรวจสอบดูว่า repo ปรากฏออกมาในรูปแบบที่สมควรจะเป็นบนหน้าของคุณ ก่อนที่จะลบมันออกไป +✏️ **ทดลองใช้ได้เลย!** นำโมเดลและ tokenizer ที่เกี่ยวข้องกับ `bert-base-cased` checkpoint และอัพโหลดขึ้นไปบน repo ใน namespace ของคุณด้วยคำสั่ง `push_to_hub()` จากนั้นลองตรวจสอบดูว่า repo ปรากฏออกมาในรูปแบบที่สมควรจะเป็นบนหน้าของคุณ ก่อนที่จะลบมันออกไป From f4fba07a5e7d7b87215cbdc59626c1927520f5ef Mon Sep 17 00:00:00 2001 From: "jomariya.son@gmail.com" Date: Sat, 2 Apr 2022 23:43:59 +0700 Subject: [PATCH 05/12] Translated chapter4/4 & Fix some of chapter4/3 --- chapters/th/chapter4/3.mdx | 8 ---- chapters/th/chapter4/4.mdx | 77 +++++++++++++++++++------------------- 2 files changed, 38 insertions(+), 47 deletions(-) diff --git a/chapters/th/chapter4/3.mdx b/chapters/th/chapter4/3.mdx index 5abf0c3d9..b63c6e6c4 100644 --- a/chapters/th/chapter4/3.mdx +++ b/chapters/th/chapter4/3.mdx @@ -146,7 +146,6 @@ model.push_to_hub("dummy-model") tokenizer.push_to_hub("dummy-model") ``` -If you belong to an organization, simply specify the `organization` argument to upload to that organization's namespace: ถ้าคุณสังกัดองค์กร คุณสามารถระบุชื่อขององค์กรใน `organization` argument เพื่ออัพโหลดเข้าไปใน namespace ขององค์กร: ```py @@ -187,10 +186,6 @@ tokenizer.push_to_hub("dummy-model", organization="huggingface", use_auth_token= ## ใช้ `huggingface_hub` Python library -The `huggingface_hub` Python library is a package which offers a set of tools for the model and datasets hubs. It provides simple methods and classes for common tasks like -getting information about repositories on the hub and managing them. It provides simple APIs that work on top of git to manage those repositories' content and to integrate the Hub -in your projects and libraries. - `huggingface_hub` Python library คือ package หนึ่งที่บรรจุชุดเครื่องมือสำหรับ hub ของโมเดลและชุดข้อมูล มันมีคำสั่งและคลาสที่เรียบง่ายไว้สำหรับงานทั่วไปอย่าง การดึงข้อมูลเกี่ยวกับ repositories บน hub และการจัดการมัน มันมี API ง่ายๆที่สามารถทำงานบน git เพื่อที่จะจัดการเนื้อหาของ repositories เหล่านั้นและบูรณาการเข้ากับ Hub ในงานโปรเจคและ libraries ของคุณ @@ -356,7 +351,6 @@ repo.git_tag() repo.git_pull() ``` -Once that is done, we save the model and tokenizer files: เมื่อโค้ดทำงานเสร็จแล้ว เราเก็บไฟล์โมเดลและ tokenizer: ```py @@ -403,7 +397,6 @@ username ของฉันคือ `lysandre` และฉันใช้ `dum git clone https://huggingface.co/lysandre/dummy ``` -I now have a folder named *dummy* in my working directory. I can `cd` into the folder and have a look at the contents: ตอนนี้ฉันมีโฟลเดอร์ชื่อ *dummy* ในไดเรกทอรีที่ฉันทำงานอยู่ (working directory) ฉันสามารถ `cd` เข้าไปในโฟลเดอร์และดูว่ามีอะไรข้างในบ้าง: ```bash @@ -603,7 +596,6 @@ git commit -m "First model version" ``` {/if} -Pushing can take a bit of time, depending on the speed of your internet connection and the size of your files: การดันไฟล์นั้นอาจจะใช้เวลาสักหน่อย ขึ้นอยู่กับความเร็วของการเชื่อมต่ออินเทอร์เน็ตและขนาดไฟล์ของคุณ: ```bash diff --git a/chapters/th/chapter4/4.mdx b/chapters/th/chapter4/4.mdx index 8d9a75817..9f609ed56 100644 --- a/chapters/th/chapter4/4.mdx +++ b/chapters/th/chapter4/4.mdx @@ -1,72 +1,71 @@ -# Building a model card +# การสร้างการ์ดโมเดล (model card) -The model card is a file which is arguably as important as the model and tokenizer files in a model repository. It is the central definition of the model, ensuring reusability by fellow community members and reproducibility of results, and providing a platform on which other members may build their artifacts. +การ์ดโมเดลเป็นไฟล์ที่เรียกได้ว่าสำคัญพอๆกับไฟล์โมเดลและ tokenizer ใน model repository มันคือคำนิยามส่วนกลางของโมเดล เป็นสิ่งที่ทำให้มั่นใจว่าสมาชิกของชุมชนสามารถนำไปใช้ได้ (reusability) และสามารถทำซ้ำและได้ผลลัพธ์เหมือนเดิมได้ (reproducibility) และมันยังจัดเตรียมแพลตฟอร์มให้สมาชิกคนอื่นๆอาจใช้สร้างสิ่งประดิษฐ์ (artifacts) ของเขาเองได้ -Documenting the training and evaluation process helps others understand what to expect of a model — and providing sufficient information regarding the data that was used and the preprocessing and postprocessing that were done ensures that the limitations, biases, and contexts in which the model is and is not useful can be identified and understood. +การสร้างหนังสืออ้างอิง (documenting) ถึงกระบวนการเทรนและประเมินผลช่วยให้ผู้อื่นเข้าใจถึงสิ่งที่คาดหวังได้จากโมเดลๆหนึ่ง และการให้ข้อมูลที่เพียงพอเกี่ยวกับข้อมูลที่ถูกใช้, กระบวนการเตรียมข้อมูล (preprocessing) และกระบวนการหลังจากใช้โมเดล (postprocessing) ที่ถูกทำมาทำให้มั่นใจถึงขีดจำกัด (limitations), ความลำเอียง (biases) และบริบท (contexts) ที่โมเดลเป็นและไม่เป็น ซึ่งเป็นสิ่งที่เป็นประโยชน์มากถ้าหากสามารถระบุและเข้าใจได้ -Therefore, creating a model card that clearly defines your model is a very important step. Here, we provide some tips that will help you with this. Creating the model card is done through the *README.md* file you saw earlier, which is a Markdown file. +ดังนั้นการสร้างการ์ดโมเดลที่อธิบายถึงโมเดลของคุณอย่างละเอียดถือเป็นขั้นตอนหนึ่งที่สำคัญมาก ในส่วนนี้เรามีเคล็ดลับบางอย่างที่จะช่วยให้คุณทำสิ่งนี้ได้ การสร้างการ์ดโมเดลนั้นถูกทำผ่านไฟล์ *README.md* ที่คุณได้เห็นก่อนหน้านี่ ซึ่งมันก็คือไฟล์ Markdown ไฟล์หนึ่ง -The "model card" concept originates from a research direction from Google, first shared in the paper ["Model Cards for Model Reporting"](https://arxiv.org/abs/1810.03993) by Margaret Mitchell et al. A lot of information contained here is based on that paper, and we recommend you take a look at it to understand why model cards are so important in a world that values reproducibility, reusability, and fairness. +แนวคิด “การ์ดโมเดล” เกิดขึ้นมาจากทิศทางของงานวิจัยชิ้นหนึ่งจาก Google ซึ่งถูกแบ่งปันครั้งแรกใน ["Model Cards for Model Reporting"](https://arxiv.org/abs/1810.03993) โดย Margaret Mitchell et al. ข้อมูลส่วนใหญ่ที่เราจะพูดถึงในที่นี้มีฐานมาจากงานวิจัยชิ้นนี้ และเราแนะนำให้คุณลองดูงานวิจัยนี้เพื่อจะได้เข้าใจถึงว่าทำไมการ์ดโมเดลถึงมีความสำคัญต่อโลกที่ให้ค่าแก่ความสามารถในการทำซ้ำ (reproducibility), ความสามารถในการนำกลับมาใช้ (reusability) และความเท่าเทียม (fairness) อย่างมาก -The model card usually starts with a very brief, high-level overview of what the model is for, followed by additional details in the following sections: +โดยทั่วไปแล้วการ์ดโมเดลมักเริ่มต้นด้วยภาพรวมแบบสรุปย่อของโมเดลว่าโมเดลนี้มีไว้ทำอะไร ตามมาด้วยข้อมูลเพิ่มเติมในส่วนต่างๆต่อไปนี้: -- Model description -- Intended uses & limitations -- How to use -- Limitations and bias -- Training data -- Training procedure -- Evaluation results +- คำอธิบายโมเดล +- การนำไปใช้งานที่ควรจะเป็นและข้อจำกัดต่างๆ +- วิธีใช้ +- ข้อจำกัดและความลำเอียง +- ข้อมูลที่ใช้เทรน +- ขั้นตอนการเทรน +- ผลจากการประเมิน -Let's take a look at what each of these sections should contain. +มาดูกันดีกว่าว่าแต่ละส่วนนี้ควรมีอะไรบ้าง -### Model description +### คำอธิบายโมเดล -The model description provides basic details about the model. This includes the architecture, version, if it was introduced in a paper, if an original implementation is available, the author, and general information about the model. Any copyright should be attributed here. General information about training procedures, parameters, and important disclaimers can also be mentioned in this section. +คำอธิบายโมเดลควรบอกรายละเอียดพื้นฐานเกี่ยวกับโมเดล ซึ่งหมายถึงสถาปัตยกรรม (architecture), เวอร์ชั่น, มาจากงานวิจัยหรือไม่, มี implementation จากแหล่งต้นทางหรือไม่, ผู้เขียน และข้อมูลทั่วไปเกี่ยวกับโมเดล ลิขสิทธิ์ทุกอย่างควรจะถูกระบุอยู่ในส่วนนี้ ข้อมูลโดยทั่วไปเกี่ยวกับกระบวนการเทรน, พารามิเตอร์ และข้อจำกัดความรับผิดชอบ (disclaimers) ที่สำคัญสามารถถูกพูดถึงในส่วนนี้ได้เช่นกัน -### Intended uses & limitations +### การนำไปใช้งานที่ควรจะเป็นและข้อจำกัดต่างๆ -Here you describe the use cases the model is intended for, including the languages, fields, and domains where it can be applied. This section of the model card can also document areas that are known to be out of scope for the model, or where it is likely to perform suboptimally. +ในส่วนนี้คุณควรอธิบายกรณีการใช้งาน (use cases) ที่โมเดลถูกตั้งใจสร้างขึ้นมาเพื่อให้ใช้งาน รวมถึงภาษา, ประเภทงาน และโดเมนที่โมเดลสามารถประยุกต์ใช้ได้ ในส่วนนี้ของการ์ดโมเดลสามารถพูดถึงเกี่ยวกับสายงานที่ไม่อยู่ในขอบเขตของโมเดล และสายงานที่โมเดลไม่สามารถปฏิบัติการได้ดีที่สุด -### How to use +### วิธีใช้ -This section should include some examples of how to use the model. This can showcase usage of the `pipeline()` function, usage of the model and tokenizer classes, and any other code you think might be helpful. +ส่วนนี้ควรมีตัวอย่างของการใช้งานโมเดล สามารถเป็นในรูปแบบของการใช้งานฟังก์ชั่น `pipeline()`, การใช้งานคลาสโมเดลและ tokenizer และโค้ดอื่นๆที่คุณคิดว่าน่าจะเป็นประโยชน์ได้ -### Training data +### ข้อมูลที่ใช้เทรน -This part should indicate which dataset(s) the model was trained on. A brief description of the dataset(s) is also welcome. +ส่วนนี้ควรระบุถึงชุดข้อมูลที่โมเดลได้ถูกเทรนมา ถ้าหากมีคำอธิบายโดยสรุปของชุดข้อมูลก็จะดีมาก -### Training procedure +### ขั้นตอนการเทรน -In this section you should describe all the relevant aspects of training that are useful from a reproducibility perspective. This includes any preprocessing and postprocessing that were done on the data, as well as details such as the number of epochs the model was trained for, the batch size, the learning rate, and so on. +ในส่วนนี้คุณควรอธิบายทุกอย่างที่เกี่ยวข้องกับการเทรนที่เป็นประโยชน์ในมุมมองของการนำไปทำซ้ำ ซึ่งควรมีกระบวนการเตรียมข้อมูล (preprocessing) และกระบวนการหลังจากใช้โมเดล (postprocessing) ที่ถูกทำไว้กับชุดข้อมูลนี้ รวมถึงรายละเอียดเกี่ยวกับจำนวนรอบ (epochs) ที่ใช้ในการเทรนโมเดล, ขนาด batch (batch size), อัตราการเรียนรู้ (learning rate) และอื่นๆ -### Variable and metrics +### ตัวแปรและเมตริก -Here you should describe the metrics you use for evaluation, and the different factors you are mesuring. Mentioning which metric(s) were used, on which dataset and which dataset split, makes it easy to compare you model's performance compared to that of other models. These should be informed by the previous sections, such as the intended users and use cases. +ส่วนนี้คุณควรอธิบายเมตริก (metrics) ที่คุณใช้ในการประเมินผล และปัจจัยต่างๆที่คุณตรวจวัด การกล่าวถึงเมตริกต่างๆที่ถูกใช้ กับชุดข้อมูลไหนและแบ่งอย่างไร ช่วยทำให้การเปรียบเทียบประสิทธิภาพของโมเดลของคุณกับโมเดลอื่นๆเป็นไปได้ง่าย ซึ่งสิ่งเหล่านี้ควรจะถูกระบุอยู่ในส่วนที่ผ่านมา เช่น ผู้ใช้และการนำไปใช้งานที่ควรจะเป็น -### Evaluation results +### ผลจากการประเมิน -Finally, provide an indication of how well the model performs on the evaluation dataset. If the model uses a decision threshold, either provide the decision threshold used in the evaluation, or provide details on evaluation at different thresholds for the intended uses. +ส่วนสุดท้าย คุณควรระบุข้อบ่งชี้ว่าโมเดลของคุณทำงานได้ดีแค่ไหนกับชุดข้อมูลสำหรับประเมินผล (evaluation dataset) ถ้าโมเดลมีการใช้เกณฑ์ในการตัดสินใจ (decision threshold) คุณควรระบุค่าที่ใช้เป็นเกณฑ์นั้นในการประเมินผล หรือระบุรายละเอียดของการประเมินผลที่เกณฑ์ต่างกันสำหรับการใช้งานที่ควรจะเป็น -## Example +## ตัวอย่าง -Check out the following for a few examples of well-crafted model cards: +ลองเข้าไปดู links เหล่านี้เป็นตัวอย่างสำหรับการ์ดโมเดลที่ถูกขัดเกลามาอย่างดี: - [`bert-base-cased`](https://huggingface.co/bert-base-cased) - [`gpt2`](https://huggingface.co/gpt2) - [`distilbert`](https://huggingface.co/distilbert-base-uncased) -More examples from different organizations and companies are available [here](https://github.com/huggingface/model_card/blob/master/examples.md). +ตัวอย่างเพิ่มเติมจากองค์กรและบริษัทต่างๆ สามารถดูได้จาก [ที่นี่](https://github.com/huggingface/model_card/blob/master/examples.md) -## Note +## หมายเหตุ -Model cards are not a requirement when publishing models, and you don't need to include all of the sections described above when you make one. However, explicit documentation of the model can only benefit future users, so we recommend that you fill in as many of the sections as possible to the best of your knowledge and ability. +การ์ดโมเดลไม่ได้เป็นหนึ่งในสิ่งที่เรียกร้อง (requirement) เมื่อจะทำการเปิดเผยโมเดลสู่สาธารณะ คุณไม่จำเป็นต้องใส่ทุกส่วนที่เราได้พูดถึงไปข้างบนถ้าคุณต้องการจะทำมัน อย่างไรก็ได้หนังสืออ้างอิงที่ชัดเจนของโมเดลสามารถสร้างประโยชน์กับผู้ใช้ในอนาคตได้ ดังนั้นเราจึงแนะนำให้คุณเติมส่วนต่างๆที่คุณรู้ให้ได้มากที่สุดเท่าที่จะเป็นไปได้ +## ข้อมูลเมตาของการ์ดโมเดล (Model card metadata) -## Model card metadata +ถ้าคุณได้ทำการสำรวจ Hugging Face Hub มาบ้างแล้ว คุณน่าจะได้เห็นบางโมเดลในหมวดหมู่ต่างๆ ที่คุณสามารถคัดกรองพวกมันได้ด้วยประเภทงาน, ภาษา, libraries และอื่นๆ หมวดหมู่ที่โมเดลๆหนึ่งอยู่ถูกระบุตามข้อมูลเมตา (metadata) ที่คุณเพิ่มเข้าไปในหัวของการ์ดโมเดล -If you have done a little exploring of the Hugging Face Hub, you should have seen that some models belong to certain categories: you can filter them by tasks, languages, libraries, and more. The categories a model belongs to are identified according to the metadata you add in the model card header. - -For example, if you take a look at the [`camembert-base` model card](https://huggingface.co/camembert-base/blob/main/README.md), you should see the following lines in the model card header: +ตัวอย่างเช่น ถ้าคุณลองดูที่ [การ์ดโมเดล `camembert-base`](https://huggingface.co/camembert-base/blob/main/README.md) คุณจะเห็นบรรทัดต่อไปนี้ในหัวการ์ดโมเดล: ``` --- @@ -77,6 +76,6 @@ datasets: --- ``` -This metadata is parsed by the Hugging Face Hub, which then identifies this model as being a French model, with an MIT license, trained on the Oscar dataset. +ข้อมูลเมตานี้ถูกแยกวิเคราะห์โดย Hugging Face Hub ซึ่งต่อจากนั้นจะถูกใช้เป็นตัวระบุว่าโมเดลนี้เป็นโมเดลภาษาฝรั่งเศส มีใบอนุญาต MIT และถูกเทรนมากับชุดข้อมูล Oscar -The [full model card specification](https://github.com/huggingface/hub-docs/blame/main/modelcard.md) allows specifying languages, licenses, tags, datasets, metrics, as well as the evaluation results the model obtained when training. +[รายละเอียดการ์ดโมเดลแบบเต็ม](https://github.com/huggingface/hub-docs/blame/main/modelcard.md) ช่วยให้สามารถระบุภาษา, ใบอนุญาต, แท็ก, ชุดข้อมูล, เมตริก รวมไปถึงผลลัพธ์จากการประเมินผลที่โมเดลได้จากการเทรน \ No newline at end of file From 06fa41a6d7fe406ad60cd3031c368be5a31c5cca Mon Sep 17 00:00:00 2001 From: "jomariya.son@gmail.com" Date: Sun, 3 Apr 2022 01:52:38 +0700 Subject: [PATCH 06/12] Translated chapter4/5 and change toctree --- chapters/th/_toctree.yml | 2 +- chapters/th/chapter4/5.mdx | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/chapters/th/_toctree.yml b/chapters/th/_toctree.yml index 8eb9239d6..7762c2889 100644 --- a/chapters/th/_toctree.yml +++ b/chapters/th/_toctree.yml @@ -9,7 +9,7 @@ - local: chapter4/4 title: การสร้างการ์ดโมเดล (model card) - local: chapter4/5 - title: จบส่วนที่ 1! + title: จบพาร์ทที่ 1! - local: chapter4/6 title: คำถามท้ายบท quiz: 4 \ No newline at end of file diff --git a/chapters/th/chapter4/5.mdx b/chapters/th/chapter4/5.mdx index 9edff8a97..e810397d8 100644 --- a/chapters/th/chapter4/5.mdx +++ b/chapters/th/chapter4/5.mdx @@ -1,7 +1,7 @@ -# Part 1 completed! +# จบพาร์ทที่ 1! -This is the end of the first part of the course! Part 2 will be released on November 15th with a big community event, see more information [here](https://huggingface.co/blog/course-launch-event). +นี่คือจุดจบของพาร์ทแรกในคอร์สนี้! พาร์ทที่ 2 จะถูกปล่อยในวันที่ 15 พฤศจิกายน พร้อมกับงานอีเว้นท์ชุมชนใหญ่ ดูรายละเอียดเพิ่มเติม [ที่นี่](https://huggingface.co/blog/course-launch-event) -You should now be able to fine-tune a pretrained model on a text classification problem (single or pairs of sentences) and upload the result to the Model Hub. To make sure you mastered this first section, you should do exactly that on a problem that interests you (and not necessarily in English if you speak another language)! You can find help in the [Hugging Face forums](https://discuss.huggingface.co/) and share your project in [this topic](https://discuss.huggingface.co/t/share-your-projects/6803) once you're finished. +ตอนนี้คุณควรจะสามารถทำ fine-tune โมเดลที่ผ่านการเทรนมาแล้ว (pretrained model) กับปัญหาการจำแนกประเภทตัวหนังสือ (text classification) (แบบประโยคเดี่ยวหรือคู่ประโยค) และอัพโหลดผลลัพธ์ขึ้นสู่ Model Hub ได้ เพื่อที่จะทำให้มั่นใจว่าคุณเชี่ยวชาญส่วนแรกนี้แล้วจริงๆ คุณควรจะฝึกทำแบบนี้เป๊ะๆกับปัญหาที่คุณสนใจ (และไม่จำเป็นจะต้องเป็นภาษาอังกฤษถ้าคุณพูดภาษาอื่น)! คุณสามารถหาความช่วยเหลือได้ใน [Hugging Face forums](https://discuss.huggingface.co/) และแบ่งปันโปรเจคของคุณได้ใน [หัวข้อนี้](https://discuss.huggingface.co/t/share-your-projects/6803) เมื่อคุณทำเสร็จ -We can't wait to see what you will build with this! +เรารอไม่ไหวแล้วที่จะได้เห็นว่าคุณจะสร้างอะไรได้บ้างจากความรู้นี้! \ No newline at end of file From fdc62e2bbc48e4ea405a17940e86213c444c77e9 Mon Sep 17 00:00:00 2001 From: "jomariya.son@gmail.com" Date: Sun, 3 Apr 2022 03:17:11 +0700 Subject: [PATCH 07/12] Translated chapter4/6 --- chapters/th/chapter4/6.mdx | 153 +++++++++++++++++++------------------ 1 file changed, 77 insertions(+), 76 deletions(-) diff --git a/chapters/th/chapter4/6.mdx b/chapters/th/chapter4/6.mdx index 6e968972f..c50a6aac5 100644 --- a/chapters/th/chapter4/6.mdx +++ b/chapters/th/chapter4/6.mdx @@ -2,128 +2,129 @@ -# End-of-chapter quiz +# คำถามท้ายบท -Let's test what you learned in this chapter! - -### 1. What are models on the Hub limited to? +มาทดสอบความรู้ที่คุณได้เรียนในบทนี้กันเถอะ! + +### 1. อะไรคือข้อจำกัดของโมเดลบน Hub? -### 2. How can you manage models on the Hub? +### 2. คุณสามารถจัดการโมเดลบน Hub ได้อย่างไร? git-lfs for large files.", + text: "ผ่าน git และ git-lfs", + explain: "ถูกต้องแล้ว! โมเดลบน Hub เป็น Git repositories แบบเรียบง่าย มีการใช้งาน git-lfs สำหรับไฟล์ขนาดใหญ่", correct: true } ]} /> -### 3. What can you do using the Hugging Face Hub web interface? +### 3. คุณสามารถใช้ web interface ของ Hugging Face Hub ทำอะไรได้บ้าง? -### 4. What is a model card? +### 4. การ์ดโมเดลคืออะไร? -### 5. Which of these objects of the 🤗 Transformers library can be directly shared on the Hub with `push_to_hub()`? +### 5. วัตถุ (objects) ใดต่อไปนี้ของ 🤗 Transformers library ที่สามารถถูกแบ่งปันได้โดยตรงบน Hub ผ่านคำสั่ง `push_to_hub()`? {#if fw === 'pt'} push_to_hub method, and using it will push all the tokenizer files (vocabulary, architecture of the tokenizer, etc.) to a given repo. That's not the only right answer, though!", + text: "tokenizer", + explain: "ถูกต้องแล้ว! tokenizer ทั้งหมดมีคำสั่ง push_to_hub และใช้มันในการดันไฟล์ทั้งหมดของ tokenizer (คำศัพท์ (vocabulary), สถาปัตยกรรมของ tokenizer และอื่นๆ) ไปยัง repo ที่กำหนดได้ แต่นี่ก็ไม่ใช่คำตอบที่ถูกเพียงข้อเดียว!" correct: true }, { - text: "A model configuration", - explain: "Right! All model configurations have the push_to_hub method, and using it will push them to a given repo. What else can you share?", + text: "model configuration", + explain: "ถูกต้องแล้ว! ไฟล์สำหรับกำหนดค่าของโมเดล (model configurations) ทั้งหมดมีคำสั่ง push_to_hub และใช้มันในการดันพวกมันขึ้นไปยัง repo ที่กำหนดได้ มีอะไรอีกที่คุณสามารถแบ่งปันได้?", correct: true }, { - text: "A model", - explain: "Correct! All models have the push_to_hub method, and using it will push them and their configuration files to a given repo. That's not all you can share, though.", + text: "model", + explain: "ถูกต้องแล้ว! โมเดลทั้งหมดมีคำสั่ง push_to_hub และใช้มันในการดันพวกมันและไฟล์กำหนดค่าของพวกมันขึ้นไปยัง repo ที่กำหนดได้ แต่นั่นก็ไม่ใช่ทั้งหมดที่คุณแบ่งปันได้", correct: true }, { - text: "A Trainer", - explain: "That's right — the Trainer also implements the push_to_hub method, and using it will upload the model, its configuration, the tokenizer, and a model card draft to a given repo. Try another answer!", + text: "Trainer", + explain: "ถูกต้อง — Trainer ก็มีคำสั่ง push_to_hub และใช้มันในการอัพโหลดโมเดล, ไฟล์กำหนดค่า, tokenizer และดราฟของการ์ดโมเดลไปยัง repo ที่กำหนดได้ ลองตอบข้ออื่นดู!", correct: true } ]} @@ -132,92 +133,92 @@ Let's test what you learned in this chapter! push_to_hub method, and using it will push all the tokenizer files (vocabulary, architecture of the tokenizer, etc.) to a given repo. That's not the only right answer, though!", + text: "tokenizer", + explain: "ถูกต้องแล้ว! tokenizer ทั้งหมดมีคำสั่ง push_to_hub และใช้มันในการดันไฟล์ทั้งหมดของ tokenizer (คำศัพท์ (vocabulary), สถาปัตยกรรมของ tokenizer และอื่นๆ) ไปยัง repo ที่กำหนดได้ แต่นี่ก็ไม่ใช่คำตอบที่ถูกเพียงข้อเดียว!" correct: true }, { - text: "A model configuration", - explain: "Right! All model configurations have the push_to_hub method, and using it will push them to a given repo. What else can you share?", + text: "model configuration", + explain: "ถูกต้องแล้ว! ไฟล์สำหรับกำหนดค่าของโมเดล (model configurations) ทั้งหมดมีคำสั่ง push_to_hub และใช้มันในการดันพวกมันขึ้นไปยัง repo ที่กำหนดได้ มีอะไรอีกที่คุณสามารถแบ่งปันได้?", correct: true }, { - text: "A model", - explain: "Correct! All models have the push_to_hub method, and using it will push them and their configuration files to a given repo. That's not all you can share, though.", + text: "model", + explain: "ถูกต้องแล้ว! โมเดลทั้งหมดมีคำสั่ง push_to_hub และใช้มันในการดันพวกมันและไฟล์กำหนดค่าของพวกมันขึ้นไปยัง repo ที่กำหนดได้ แต่นั่นก็ไม่ใช่ทั้งหมดที่คุณแบ่งปันได้", correct: true }, { - text: "All of the above with a dedicated callback", - explain: "That's right — the PushToHubCallback will regularly send all of those objects to a repo during training.", + text: "ทั้งหมดที่กล่าวมารวมกับ callback ที่อุทิศให้", + explain: "ถูกต้อง — โดยปกติ PushToHubCallback จะส่งวัตถุทั้งหมดเหล่านั้นไปยัง repo ระหว่างการเทรน", correct: true } ]} /> {/if} -### 6. What is the first step when using the `push_to_hub()` method or the CLI tools? +### 6. อะไรคือขั้นตอนแรกในการรใช้คำสั่ง `push_to_hub()` หรือเครื่องมือ CLI? -### 7. You're using a model and a tokenizer — how can you upload them to the Hub? +### 7. คุณกำลังใช้งานโมเดลและ tokenizer อยู่ — คุณจะสามารถอัพโหลดพวกมันขึ้นไปบน Hub ได้อย่างไร? huggingface_hub utility.", - explain: "Models and tokenizers already benefit from huggingface_hub utilities: no need for additional wrapping!" + text: "ภายใน Python runtime คลุมพวกมันเอาไว้ด้วย huggingface_hub utility", + explain: "โมเดลและ tokenizers ถ้ารับประโยชน์จาก huggingface_hub utilities อยู่แล้ว: ไม่จำเป็นจะต้องมีการคลุมเพิ่ม!" }, { - text: "By saving them to disk and calling transformers-cli upload-model", - explain: "The command upload-model does not exist." + text: "โดยการบันทึกพวกมันลงบนเครื่องและเรียกใช้คำสั่ง transformers-cli upload-model", + explain: "ไม่มีคำสั่ง upload-model นี้อยู่" } ]} /> -### 8. Which git operations can you do with the `Repository` class? +### 8. มีการดำเนินการ git (git operations) ใดบ้างที่คุณสามารถทำได้กับคลาส `Repository`? git_commit() method is there for that.", + text: "commit", + explain: "ถูกต้อง คำสั่ง git_commit() มีไว้สำหรับสิ่งนี้", correct: true }, { - text: "A pull", - explain: "That is the purpose of the git_pull() method.", + text: "pull", + explain: "นั่นคือวัตถุประสงค์ของคำสั่ง git_pull()", correct: true }, { - text: "A push", - explain: "The method git_push() does this.", + text: "push", + explain: "คำสั่ง git_push() มีไว้ทำสิ่งนี้", correct: true }, { - text: "A merge", - explain: "No, that operation will never be possible with this API." + text: "merge", + explain: "ไม่ การดำเนินการนี้ไม่สามารถทำได้กับ API นี้" } ]} /> From a28079ee62e6b192b1846fca28f665cb35cb7f12 Mon Sep 17 00:00:00 2001 From: "jomariya.son@gmail.com" Date: Sun, 3 Apr 2022 11:03:59 +0700 Subject: [PATCH 08/12] Fixed typos --- chapters/th/chapter4/6.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/th/chapter4/6.mdx b/chapters/th/chapter4/6.mdx index c50a6aac5..bd6740174 100644 --- a/chapters/th/chapter4/6.mdx +++ b/chapters/th/chapter4/6.mdx @@ -156,7 +156,7 @@ /> {/if} -### 6. อะไรคือขั้นตอนแรกในการรใช้คำสั่ง `push_to_hub()` หรือเครื่องมือ CLI? +### 6. อะไรคือขั้นตอนแรกในการใช้คำสั่ง `push_to_hub()` หรือเครื่องมือ CLI? Date: Mon, 4 Apr 2022 20:40:53 +0700 Subject: [PATCH 09/12] Update chapters/th/_toctree.yml Co-authored-by: lewtun --- chapters/th/_toctree.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/th/_toctree.yml b/chapters/th/_toctree.yml index be7e438dd..353615610 100644 --- a/chapters/th/_toctree.yml +++ b/chapters/th/_toctree.yml @@ -11,7 +11,7 @@ - title: 4. การแบ่งปันโมเดลและ tokenizers sections: - local: chapter4/1 - title: Hugging Face Hub + title: The Hugging Face Hub - local: chapter4/2 title: การใช้งานโมเดลที่ผ่านการเทรนมาแล้ว (pretrained models) - local: chapter4/3 From b1904503839c2de7bc148439887c8db354a92f57 Mon Sep 17 00:00:00 2001 From: Ariya Sontrapornpol <73450708+jomariya23156@users.noreply.github.com> Date: Mon, 4 Apr 2022 20:41:19 +0700 Subject: [PATCH 10/12] Update chapters/th/chapter4/6.mdx Co-authored-by: lewtun --- chapters/th/chapter4/6.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/th/chapter4/6.mdx b/chapters/th/chapter4/6.mdx index bd6740174..4eabd5cba 100644 --- a/chapters/th/chapter4/6.mdx +++ b/chapters/th/chapter4/6.mdx @@ -109,7 +109,7 @@ choices={[ { text: "tokenizer", - explain: "ถูกต้องแล้ว! tokenizer ทั้งหมดมีคำสั่ง push_to_hub และใช้มันในการดันไฟล์ทั้งหมดของ tokenizer (คำศัพท์ (vocabulary), สถาปัตยกรรมของ tokenizer และอื่นๆ) ไปยัง repo ที่กำหนดได้ แต่นี่ก็ไม่ใช่คำตอบที่ถูกเพียงข้อเดียว!" + explain: "ถูกต้องแล้ว! tokenizer ทั้งหมดมีคำสั่ง push_to_hub และใช้มันในการดันไฟล์ทั้งหมดของ tokenizer (คำศัพท์ (vocabulary), สถาปัตยกรรมของ tokenizer และอื่นๆ) ไปยัง repo ที่กำหนดได้ แต่นี่ก็ไม่ใช่คำตอบที่ถูกเพียงข้อเดียว!", correct: true }, { From aa403a396703210cf2741b09b0246bd30228e297 Mon Sep 17 00:00:00 2001 From: Ariya Sontrapornpol <73450708+jomariya23156@users.noreply.github.com> Date: Mon, 4 Apr 2022 20:41:37 +0700 Subject: [PATCH 11/12] Update chapters/th/chapter4/6.mdx Co-authored-by: lewtun --- chapters/th/chapter4/6.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/th/chapter4/6.mdx b/chapters/th/chapter4/6.mdx index 4eabd5cba..078accc9a 100644 --- a/chapters/th/chapter4/6.mdx +++ b/chapters/th/chapter4/6.mdx @@ -134,7 +134,7 @@ choices={[ { text: "tokenizer", - explain: "ถูกต้องแล้ว! tokenizer ทั้งหมดมีคำสั่ง push_to_hub และใช้มันในการดันไฟล์ทั้งหมดของ tokenizer (คำศัพท์ (vocabulary), สถาปัตยกรรมของ tokenizer และอื่นๆ) ไปยัง repo ที่กำหนดได้ แต่นี่ก็ไม่ใช่คำตอบที่ถูกเพียงข้อเดียว!" + explain: "ถูกต้องแล้ว! tokenizer ทั้งหมดมีคำสั่ง push_to_hub และใช้มันในการดันไฟล์ทั้งหมดของ tokenizer (คำศัพท์ (vocabulary), สถาปัตยกรรมของ tokenizer และอื่นๆ) ไปยัง repo ที่กำหนดได้ แต่นี่ก็ไม่ใช่คำตอบที่ถูกเพียงข้อเดียว!", correct: true }, { From 55b522f953debac7ccbb15757b9a5ab4f49b60a5 Mon Sep 17 00:00:00 2001 From: Ariya Sontrapornpol <73450708+jomariya23156@users.noreply.github.com> Date: Mon, 4 Apr 2022 20:46:55 +0700 Subject: [PATCH 12/12] Update chapter4/1 topic --- chapters/th/chapter4/1.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chapters/th/chapter4/1.mdx b/chapters/th/chapter4/1.mdx index 3078aba53..c4a18cd1e 100644 --- a/chapters/th/chapter4/1.mdx +++ b/chapters/th/chapter4/1.mdx @@ -1,4 +1,4 @@ -# Hugging Face Hub +# The Hugging Face Hub [Hugging Face Hub](https://huggingface.co/) –- เว็บไซต์หลักของเรา –- เป็นแพลตฟอร์มกลางที่ทุกคนสามารถค้นหาโมเดลและชุดข้อมูลที่ล้ำสมัยที่สุด (state-of-the-art) และสามารถนำไปใช้งาน รวมถึงมีส่วนร่วมได้ เรามีโมเดลที่เปิดให้ใช้ได้อย่างเป็นสาธารณะที่หลากหลายมากกว่า 10,000 โมเดลให้เลือกใช้ ซึ่งในบทนี้เราจะมาเจาะลึกลงในเรื่องของโมเดล และเราจะพูดถึงชุดข้อมูลในบทที่ 5 @@ -14,4 +14,4 @@ -ในส่วนนี้คุณจำเป็นที่จะต้องมีบัญชี huggingface.co เพื่อที่จะทำตาม เพราะเราจะมีการสร้างและจัดการ repositories บน Hugging Face Hub: [สร้างบัญชี](https://huggingface.co/join) \ No newline at end of file +ในส่วนนี้คุณจำเป็นที่จะต้องมีบัญชี huggingface.co เพื่อที่จะทำตาม เพราะเราจะมีการสร้างและจัดการ repositories บน Hugging Face Hub: [สร้างบัญชี](https://huggingface.co/join)