Spaces:
Runtime error
Runtime error
updates
Browse files- params.yml +5 -2
- src/__init__.py +12 -8
- src/models/__init__.py +4 -4
- src/models/evaluate_model.py +0 -1
- src/models/model.py +33 -0
- src/models/train_model.py +3 -0
- src/visualization/visualize.py +5 -4
params.yml
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
data: cnn_dailymail
|
2 |
batch_size: 2
|
3 |
num_workers: 2
|
@@ -8,6 +9,8 @@ epochs: 5
|
|
8 |
source_dir: src
|
9 |
model_dir: models
|
10 |
metric: rouge
|
11 |
-
split: 0.
|
12 |
use_gpu: True
|
13 |
-
visualise: True
|
|
|
|
|
|
1 |
+
name: summarsiation
|
2 |
data: cnn_dailymail
|
3 |
batch_size: 2
|
4 |
num_workers: 2
|
|
|
9 |
source_dir: src
|
10 |
model_dir: models
|
11 |
metric: rouge
|
12 |
+
split: 0.001
|
13 |
use_gpu: True
|
14 |
+
visualise: True
|
15 |
+
hf_username: gagan3012
|
16 |
+
upload_to_hf: True
|
src/__init__.py
CHANGED
@@ -1,8 +1,12 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
from src.
|
5 |
-
from src.data.
|
6 |
-
from src.
|
7 |
-
from src.
|
8 |
-
import
|
|
|
|
|
|
|
|
|
|
1 |
+
import os # noqa: F401
|
2 |
+
import sys # noqa: F401
|
3 |
+
|
4 |
+
from src.data.make_dataset import make_dataset # noqa: F401
|
5 |
+
from src.data.process_data import process_data # noqa: F401
|
6 |
+
from src.models.evaluate_model import evaluate_model # noqa: F401
|
7 |
+
from src.models.model import Summarization # noqa: F401
|
8 |
+
from src.models.predict_model import predict_model # noqa: F401
|
9 |
+
from src.models.train_model import train_model # noqa: F401
|
10 |
+
from src.visualization.visualize import visualize # noqa: F401
|
11 |
+
|
12 |
+
sys.path.append(os.path.dirname(os.path.realpath(__file__))) # noqa: F401
|
src/models/__init__.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
from .model import Summarization
|
2 |
-
from .train_model import train_model
|
3 |
-
from .predict_model import predict_model
|
4 |
-
from .evaluate_model import evaluate_model
|
|
|
1 |
+
from .model import Summarization # noqa: F401
|
2 |
+
from .train_model import train_model # noqa: F401
|
3 |
+
from .predict_model import predict_model # noqa: F401
|
4 |
+
from .evaluate_model import evaluate_model # noqa: F401
|
src/models/evaluate_model.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
import dagshub
|
2 |
import yaml
|
3 |
|
4 |
from model import Summarization
|
|
|
|
|
1 |
import yaml
|
2 |
|
3 |
from model import Summarization
|
src/models/model.py
CHANGED
@@ -1,5 +1,10 @@
|
|
|
|
|
|
|
|
|
|
1 |
import torch
|
2 |
import pandas as pd
|
|
|
3 |
from transformers import (
|
4 |
AdamW,
|
5 |
T5ForConditionalGeneration,
|
@@ -547,3 +552,31 @@ class Summarization:
|
|
547 |
"rougeLsum High F1": results["rougeLsum"].high.fmeasure,
|
548 |
}
|
549 |
return output
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import shutil
|
2 |
+
from getpass import getpass
|
3 |
+
from pathlib import Path
|
4 |
+
|
5 |
import torch
|
6 |
import pandas as pd
|
7 |
+
from huggingface_hub import HfApi, Repository
|
8 |
from transformers import (
|
9 |
AdamW,
|
10 |
T5ForConditionalGeneration,
|
|
|
552 |
"rougeLsum High F1": results["rougeLsum"].high.fmeasure,
|
553 |
}
|
554 |
return output
|
555 |
+
|
556 |
+
def upload(self, hf_username, model_name):
|
557 |
+
hf_password = getpass("Enter your HuggingFace password")
|
558 |
+
if Path("./models").exists():
|
559 |
+
shutil.rmtree("./models")
|
560 |
+
token = HfApi().login(username=hf_username, password=hf_password)
|
561 |
+
del hf_password
|
562 |
+
model_url = HfApi().create_repo(token=token, name=model_name, exist_ok=True)
|
563 |
+
model_repo = Repository(
|
564 |
+
"./model",
|
565 |
+
clone_from=model_url,
|
566 |
+
use_auth_token=token,
|
567 |
+
git_email=f"{hf_username}@users.noreply.huggingface.co",
|
568 |
+
git_user=hf_username,
|
569 |
+
)
|
570 |
+
|
571 |
+
readme_txt = f"""
|
572 |
+
---
|
573 |
+
Summarisation model {model_name}
|
574 |
+
""".strip()
|
575 |
+
|
576 |
+
(Path(model_repo.local_dir) / "README.md").write_text(readme_txt)
|
577 |
+
self.save_model()
|
578 |
+
commit_url = model_repo.push_to_hub()
|
579 |
+
|
580 |
+
print("Check out your model at:")
|
581 |
+
print(commit_url)
|
582 |
+
print(f"https://huggingface.co/{hf_username}/{model_name}")
|
src/models/train_model.py
CHANGED
@@ -43,6 +43,9 @@ def train_model():
|
|
43 |
with open("reports/training_metrics.txt", "w") as fp:
|
44 |
json.dump(data, fp)
|
45 |
|
|
|
|
|
|
|
46 |
|
47 |
if __name__ == "__main__":
|
48 |
train_model()
|
|
|
43 |
with open("reports/training_metrics.txt", "w") as fp:
|
44 |
json.dump(data, fp)
|
45 |
|
46 |
+
if params["upload_to_hf"]:
|
47 |
+
model.upload(hf_username=params["hf_username"], model_name=params["name"])
|
48 |
+
|
49 |
|
50 |
if __name__ == "__main__":
|
51 |
train_model()
|
src/visualization/visualize.py
CHANGED
@@ -5,12 +5,13 @@ from models import predict_model
|
|
5 |
|
6 |
|
7 |
def visualize():
|
8 |
-
st.write(
|
9 |
st.markdown(
|
10 |
-
|
11 |
*For additional questions and inquiries, please contact **Gagan Bhatia** via [LinkedIn](
|
12 |
https://www.linkedin.com/in/gbhatia30/) or [Github](https://github.com/gagan3012).*
|
13 |
-
|
|
|
14 |
|
15 |
text = st.text_area("Enter text here")
|
16 |
if st.button("Generate Summary"):
|
@@ -27,5 +28,5 @@ if __name__ == "__main__":
|
|
27 |
with open("params.yml") as f:
|
28 |
params = yaml.safe_load(f)
|
29 |
|
30 |
-
if params[
|
31 |
visualize()
|
|
|
5 |
|
6 |
|
7 |
def visualize():
|
8 |
+
st.write("# Summarization UI")
|
9 |
st.markdown(
|
10 |
+
"""
|
11 |
*For additional questions and inquiries, please contact **Gagan Bhatia** via [LinkedIn](
|
12 |
https://www.linkedin.com/in/gbhatia30/) or [Github](https://github.com/gagan3012).*
|
13 |
+
"""
|
14 |
+
)
|
15 |
|
16 |
text = st.text_area("Enter text here")
|
17 |
if st.button("Generate Summary"):
|
|
|
28 |
with open("params.yml") as f:
|
29 |
params = yaml.safe_load(f)
|
30 |
|
31 |
+
if params["visualise"]:
|
32 |
visualize()
|