Instructions to use patomp/thai-light-multimodal-distill with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use patomp/thai-light-multimodal-distill with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="patomp/thai-light-multimodal-distill", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("patomp/thai-light-multimodal-distill", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download encoder.py from patomp/thai-light-multimodal-distill: direct link, hf CLI and curl.
- Browser
- Download file 891 Bytes
-
https://huggingface.co/patomp/thai-light-multimodal-distill/resolve/main/encoder.py
- Command line
-
hf download hf://patomp/thai-light-multimodal-distill/encoder.py
-
curl -L -o encoder.py https://huggingface.co/patomp/thai-light-multimodal-distill/resolve/main/encoder.py
891 Bytes
| from transformers import PreTrainedModel | |
| from pythainlp import word_vector | |
| import torch | |
| from .configuration import ThaiLightWeightEncoderConfig | |
| from .projector import Projector | |
| class ThaiLightWeightEncoderModel(PreTrainedModel): | |
| config_class = ThaiLightWeightEncoderConfig | |
| def __init__(self, config): | |
| super().__init__(config) | |
| self.wv = word_vector.WordVector(model_name=config.word_vector_model_name) | |
| self.projector = Projector( | |
| input_embedding_dim=config.input_embedding_dim, | |
| final_embedding_dim=config.final_embedding_dim, | |
| dropout=config.dropout | |
| ) | |
| def forward(self, text: str): | |
| embed = self.wv.sentence_vectorizer(text, use_mean=True)[0] | |
| proj_embed = self.projector(torch.from_numpy(embed).float()) | |
| proj_embed = proj_embed.to("cpu").detach().numpy() | |
| return proj_embed |