songhieng commited on
Commit
d64c51c
Β·
verified Β·
1 Parent(s): 2b748f0

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +99 -146
README.md CHANGED
@@ -20,192 +20,145 @@ pipeline_tag: summarization
20
  <!-- Provide a quick summary of what the model is/does. -->
21
 
22
 
 
23
 
24
- ## Model Details
25
-
26
- ### Model Description
27
-
28
- <!-- Provide a longer summary of what this model is. -->
29
-
30
- This is the model card of a πŸ€— transformers model that has been pushed on the Hub. This model card has been automatically generated.
31
-
32
- - **Developed by:** [More Information Needed]
33
- - **Funded by [optional]:** [More Information Needed]
34
- - **Shared by [optional]:** [More Information Needed]
35
- - **Model type:** [More Information Needed]
36
- - **Language(s) (NLP):** [More Information Needed]
37
- - **License:** [More Information Needed]
38
- - **Finetuned from model [optional]:** [More Information Needed]
39
-
40
- ### Model Sources [optional]
41
-
42
- <!-- Provide the basic links for the model. -->
43
-
44
- - **Repository:** [More Information Needed]
45
- - **Paper [optional]:** [More Information Needed]
46
- - **Demo [optional]:** [More Information Needed]
47
-
48
- ## Uses
49
-
50
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
51
-
52
- ### Direct Use
53
-
54
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
55
-
56
- [More Information Needed]
57
-
58
- ### Downstream Use [optional]
59
-
60
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
61
-
62
- [More Information Needed]
63
-
64
- ### Out-of-Scope Use
65
-
66
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
67
-
68
- [More Information Needed]
69
-
70
- ## Bias, Risks, and Limitations
71
-
72
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
73
-
74
- [More Information Needed]
75
-
76
- ### Recommendations
77
-
78
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
79
-
80
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
81
 
82
- ## How to Get Started with the Model
83
 
84
- Use the code below to get started with the model.
85
-
86
- [More Information Needed]
87
-
88
- ## Training Details
89
-
90
- ### Training Data
91
-
92
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
93
-
94
- [More Information Needed]
95
-
96
- ### Training Procedure
97
-
98
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
99
-
100
- #### Preprocessing [optional]
101
-
102
- [More Information Needed]
103
-
104
-
105
- #### Training Hyperparameters
106
-
107
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
108
-
109
- #### Speeds, Sizes, Times [optional]
110
-
111
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
112
-
113
- [More Information Needed]
114
-
115
- ## Evaluation
116
-
117
- <!-- This section describes the evaluation protocols and provides the results. -->
118
-
119
- ### Testing Data, Factors & Metrics
120
-
121
- #### Testing Data
122
-
123
- <!-- This should link to a Dataset Card if possible. -->
124
-
125
- [More Information Needed]
126
-
127
- #### Factors
128
-
129
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
130
 
131
- [More Information Needed]
 
 
 
 
 
 
 
 
132
 
133
- #### Metrics
134
 
135
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
136
 
137
- [More Information Needed]
138
 
139
- ### Results
 
 
140
 
141
- [More Information Needed]
142
 
143
- #### Summary
144
 
 
 
145
 
 
 
 
 
146
 
147
- ## Model Examination [optional]
148
 
149
- <!-- Relevant interpretability work for the model goes here -->
150
 
151
- [More Information Needed]
 
 
 
 
 
 
152
 
153
- ## Environmental Impact
 
 
 
154
 
155
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
156
 
157
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
 
158
 
159
- - **Hardware Type:** [More Information Needed]
160
- - **Hours used:** [More Information Needed]
161
- - **Cloud Provider:** [More Information Needed]
162
- - **Compute Region:** [More Information Needed]
163
- - **Carbon Emitted:** [More Information Needed]
164
 
165
- ## Technical Specifications [optional]
166
 
167
- ### Model Architecture and Objective
 
168
 
169
- [More Information Needed]
170
 
171
- ### Compute Infrastructure
 
 
 
 
 
172
 
173
- [More Information Needed]
 
174
 
175
- #### Hardware
176
 
177
- [More Information Needed]
178
 
179
- #### Software
 
180
 
181
- [More Information Needed]
182
 
183
- ## Citation [optional]
 
 
 
 
 
184
 
185
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
 
186
 
187
- **BibTeX:**
188
 
189
- [More Information Needed]
190
 
191
- **APA:**
 
 
 
192
 
193
- [More Information Needed]
194
 
195
- ## Glossary [optional]
 
 
 
196
 
197
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
198
 
199
- [More Information Needed]
 
 
 
 
 
 
 
 
200
 
201
- ## More Information [optional]
202
 
203
- [More Information Needed]
204
 
205
- ## Model Card Authors [optional]
206
 
207
- [More Information Needed]
208
 
209
- ## Model Card Contact
210
 
211
- [More Information Needed]
 
20
  <!-- Provide a quick summary of what the model is/does. -->
21
 
22
 
23
+ # Khmer mT5 Summarization Model (1024 Tokens) - V2
24
 
25
+ ## Introduction
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
+ This repository contains an improved version of the Khmer mT5 summarization model, **songhieng/khmer-mt5-summarization-1024tk-V2**. This version has been trained on an expanded dataset, including data from [kimleang123/rfi_news](https://huggingface.co/datasets/kimleang123/rfi_news), allowing for improved summarization performance on Khmer text.
28
 
29
+ ## Model Details
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
+ - **Base Model:** `google/mt5-small`
32
+ - **Fine-tuned for:** Khmer text summarization with extended input length
33
+ - **Training Dataset:** `kimleang123/rfi_news` + previous dataset
34
+ - **Framework:** Hugging Face `transformers`
35
+ - **Task Type:** Sequence-to-Sequence (Seq2Seq)
36
+ - **Input:** Khmer text (articles, paragraphs, or documents) up to 1024 tokens
37
+ - **Output:** Summarized Khmer text
38
+ - **Training Hardware:** GPU (Tesla T4)
39
+ - **Evaluation Metric:** ROUGE Score
40
 
41
+ ## Installation & Setup
42
 
43
+ ### 1️⃣ Install Dependencies
44
 
45
+ Ensure you have `transformers`, `torch`, and `datasets` installed:
46
 
47
+ ```bash
48
+ pip install transformers torch datasets
49
+ ```
50
 
51
+ ### 2️⃣ Load the Model
52
 
53
+ To load and use the fine-tuned model:
54
 
55
+ ```python
56
+ from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
57
 
58
+ model_name = "songhieng/khmer-mt5-summarization-1024tk-V2"
59
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
60
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
61
+ ```
62
 
63
+ ## How to Use
64
 
65
+ ### 1️⃣ Using Python Code
66
 
67
+ ```python
68
+ def summarize_khmer(text, max_length=150):
69
+ input_text = f"summarize: {text}"
70
+ inputs = tokenizer(input_text, return_tensors="pt", truncation=True, max_length=1024)
71
+ summary_ids = model.generate(**inputs, max_length=max_length, num_beams=5, length_penalty=2.0, early_stopping=True)
72
+ summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
73
+ return summary
74
 
75
+ khmer_text = "αž€αž˜αŸ’αž–αž»αž‡αžΆαž˜αžΆαž“αž”αŸ’αžšαž‡αžΆαž‡αž“αž”αŸ’αžšαž˜αžΆαžŽ ៑៦ αž›αžΆαž“αž“αžΆαž€αŸ‹ αž αžΎαž™αžœαžΆαž‚αžΊαž‡αžΆαž”αŸ’αžšαž‘αŸαžŸαž“αŸ…αžαŸ†αž”αž“αŸ‹αž’αžΆαžŸαŸŠαžΈαž’αžΆαž‚αŸ’αž“αŸαž™αŸαŸ”"
76
+ summary = summarize_khmer(khmer_text)
77
+ print("Khmer Summary:", summary)
78
+ ```
79
 
80
+ ### 2️⃣ Using Hugging Face Pipeline
81
 
82
+ ```python
83
+ from transformers import pipeline
84
 
85
+ summarizer = pipeline("summarization", model="songhieng/khmer-mt5-summarization-1024tk-V2")
86
+ khmer_text = "αž€αž˜αŸ’αž–αž»αž‡αžΆαž˜αžΆαž“αž”αŸ’αžšαž‡αžΆαž‡αž“αž”αŸ’αžšαž˜αžΆαžŽ ៑៦ αž›αžΆαž“αž“αžΆαž€αŸ‹ αž αžΎαž™αžœαžΆαž‚αžΊαž‡αžΆαž”αŸ’αžšαž‘αŸαžŸαž“αŸ…αžαŸ†αž”αž“αŸ‹αž’αžΆαžŸαŸŠαžΈαž’αžΆαž‚αŸ’αž“αŸαž™αŸαŸ”"
87
+ summary = summarizer(khmer_text, max_length=150, min_length=30, do_sample=False)
88
+ print("Khmer Summary:", summary[0]['summary_text'])
89
+ ```
90
 
91
+ ### 3️⃣ Deploy as an API using FastAPI
92
 
93
+ ```python
94
+ from fastapi import FastAPI
95
 
96
+ app = FastAPI()
97
 
98
+ @app.post("/summarize/")
99
+ def summarize(text: str):
100
+ inputs = tokenizer(f"summarize: {text}", return_tensors="pt", truncation=True, max_length=1024)
101
+ summary_ids = model.generate(**inputs, max_length=150, num_beams=5, length_penalty=2.0, early_stopping=True)
102
+ summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
103
+ return {"summary": summary}
104
 
105
+ # Run with: uvicorn filename:app --reload
106
+ ```
107
 
108
+ ## Model Evaluation
109
 
110
+ The model was evaluated using **ROUGE scores**, which measure the similarity between the generated summaries and the reference summaries.
111
 
112
+ ```python
113
+ from datasets import load_metric
114
 
115
+ rouge = load_metric("rouge")
116
 
117
+ def compute_metrics(pred):
118
+ labels_ids = pred.label_ids
119
+ pred_ids = pred.predictions
120
+ decoded_preds = tokenizer.batch_decode(pred_ids, skip_special_tokens=True)
121
+ decoded_labels = tokenizer.batch_decode(labels_ids, skip_special_tokens=True)
122
+ return rouge.compute(predictions=decoded_preds, references=decoded_labels)
123
 
124
+ trainer.evaluate()
125
+ ```
126
 
127
+ ## Saving & Uploading the Model
128
 
129
+ After fine-tuning, the model can be uploaded to the Hugging Face Hub:
130
 
131
+ ```python
132
+ model.push_to_hub("songhieng/khmer-mt5-summarization-1024tk-V2")
133
+ tokenizer.push_to_hub("songhieng/khmer-mt5-summarization-1024tk-V2")
134
+ ```
135
 
136
+ To download it later:
137
 
138
+ ```python
139
+ model = AutoModelForSeq2SeqLM.from_pretrained("songhieng/khmer-mt5-summarization-1024tk-V2")
140
+ tokenizer = AutoTokenizer.from_pretrained("songhieng/khmer-mt5-summarization-1024tk-V2")
141
+ ```
142
 
143
+ ## Summary
144
 
145
+ | **Feature** | **Details** |
146
+ |-----------------------|-------------------------------------------------|
147
+ | **Base Model** | `google/mt5-small` |
148
+ | **Task** | Summarization |
149
+ | **Language** | Khmer (αžαŸ’αž˜αŸ‚αžš) |
150
+ | **Dataset** | `kimleang123/rfi_news` + previous dataset |
151
+ | **Framework** | Hugging Face Transformers |
152
+ | **Evaluation Metric** | ROUGE Score |
153
+ | **Deployment** | Hugging Face Model Hub, API (FastAPI), Python Code |
154
 
155
+ ## Contributing
156
 
157
+ Contributions are welcome! Feel free to **open issues or submit pull requests** if you have any improvements or suggestions.
158
 
159
+ ### Contact
160
 
161
+ If you have any questions, feel free to reach out via [Hugging Face Discussions](https://huggingface.co/) or create an issue in the repository.
162
 
163
+ **Built for the Khmer NLP Community**
164