Update README.md
Browse files
README.md
CHANGED
|
@@ -37,4 +37,73 @@ Herberta combines the strengths of modern pretraining techniques and domain know
|
|
| 37 |
"num_hidden_layers": 24,
|
| 38 |
"torch_dtype": "float32",
|
| 39 |
"vocab_size": 21128
|
| 40 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
"num_hidden_layers": 24,
|
| 38 |
"torch_dtype": "float32",
|
| 39 |
"vocab_size": 21128
|
| 40 |
+
}
|
| 41 |
+
### requirements
|
| 42 |
+
"transformers_version": "4.45.1"
|
| 43 |
+
```bash
|
| 44 |
+
pip install herberta
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
### Quickstart
|
| 48 |
+
|
| 49 |
+
#### Use Huggingface
|
| 50 |
+
```python
|
| 51 |
+
from transformers import AutoTokenizer, AutoModel
|
| 52 |
+
|
| 53 |
+
# Replace "XiaoEnn/herberta" with the Hugging Face model repository name
|
| 54 |
+
model_name = "XiaoEnn/herberta"
|
| 55 |
+
|
| 56 |
+
# Load tokenizer and model
|
| 57 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 58 |
+
model = AutoModel.from_pretrained(model_name)
|
| 59 |
+
|
| 60 |
+
# Input text
|
| 61 |
+
text = "中医理论是我国传统文化的瑰宝。"
|
| 62 |
+
|
| 63 |
+
# Tokenize and prepare input
|
| 64 |
+
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding="max_length", max_length=128)
|
| 65 |
+
|
| 66 |
+
# Get the model's outputs
|
| 67 |
+
with torch.no_grad():
|
| 68 |
+
outputs = model(**inputs)
|
| 69 |
+
|
| 70 |
+
# Get the embedding (sentence-level average pooling)
|
| 71 |
+
sentence_embedding = outputs.last_hidden_state.mean(dim=1)
|
| 72 |
+
|
| 73 |
+
print("Embedding shape:", sentence_embedding.shape)
|
| 74 |
+
print("Embedding vector:", sentence_embedding)
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
#### LocalModel
|
| 79 |
+
```python
|
| 80 |
+
from transformers import BertTokenizer, BertForMaskedLM
|
| 81 |
+
|
| 82 |
+
# Load the model and tokenizer
|
| 83 |
+
model_name = "Chengfengke/herberta"
|
| 84 |
+
tokenizer = BertTokenizer.from_pretrained(model_name)
|
| 85 |
+
model = BertForMaskedLM.from_pretrained(model_name)
|
| 86 |
+
inputs = tokenizer("This is an example text for herbal medicine.", return_tensors="pt")
|
| 87 |
+
outputs = model(**inputs)
|
| 88 |
+
```
|
| 89 |
+
|
| 90 |
+
## Citation
|
| 91 |
+
|
| 92 |
+
If you find our work helpful, feel free to give us a cite.
|
| 93 |
+
|
| 94 |
+
```bibtex
|
| 95 |
+
@misc{herberta-embedding,
|
| 96 |
+
title = {Herberta: A Pretrain_Bert_Model for TCM_herb and downstream Tasks as Text Embedding Generation},
|
| 97 |
+
url = {https://github.com/15392778677/herberta},
|
| 98 |
+
author = {Yehan Yang,Xinhan Zheng},
|
| 99 |
+
month = {December},
|
| 100 |
+
year = {2024}
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
@article{herbert-technical-report,
|
| 104 |
+
title={Herbert: A Pretrain_Bert_Model for TCM_herb and downstream Tasks as Text Embedding Generation},
|
| 105 |
+
author={Yehan Yang,Xinhan Zheng},
|
| 106 |
+
institution={Beijing Angopro Technology Co., Ltd.},
|
| 107 |
+
year={2024},
|
| 108 |
+
note={Presented at the 2024 Machine Learning Applications Conference (MLAC)}
|
| 109 |
+
}
|