Razavipour
commited on
Commit
β’
966ee03
1
Parent(s):
ca2dae7
Upload 11 files
Browse files- README.md +4 -5
- app.py +45 -0
- requirements.txt +3 -0
- summary_generation_Led_4/config.json +54 -0
- summary_generation_Led_4/generation_config.json +8 -0
- summary_generation_Led_4/merges.txt +0 -0
- summary_generation_Led_4/model.safetensors +3 -0
- summary_generation_Led_4/special_tokens_map.json +51 -0
- summary_generation_Led_4/tokenizer_config.json +56 -0
- summary_generation_Led_4/training_args.bin +3 -0
- summary_generation_Led_4/vocab.json +0 -0
README.md
CHANGED
@@ -1,13 +1,12 @@
|
|
1 |
---
|
2 |
-
title: Spoiler Alert
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.44.0
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
-
short_description: non-spoiler-Plot-Summary-Generator
|
11 |
---
|
12 |
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: Spoiler Alert
|
3 |
+
emoji: π
|
4 |
+
colorFrom: gray
|
5 |
+
colorTo: indigo
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.44.0
|
8 |
app_file: app.py
|
9 |
pinned: false
|
|
|
10 |
---
|
11 |
|
12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import LEDForConditionalGeneration, LEDTokenizer
|
3 |
+
import torch
|
4 |
+
from datasets import load_dataset
|
5 |
+
import re
|
6 |
+
|
7 |
+
# Set device to GPU if available
|
8 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
9 |
+
|
10 |
+
# Load the LED model and tokenizer
|
11 |
+
model = LEDForConditionalGeneration.from_pretrained("./summary_generation_Led_4").to(device)
|
12 |
+
tokenizer = LEDTokenizer.from_pretrained("./summary_generation_Led_4")
|
13 |
+
|
14 |
+
# Normalize the input text (plot synopsis)
|
15 |
+
def normalize_text(text):
|
16 |
+
text = text.lower() # Lowercase the text
|
17 |
+
text = re.sub(r'\s+', ' ', text).strip() # Remove extra spaces and newlines
|
18 |
+
text = re.sub(r'[^\w\s]', '', text) # Remove non-alphanumeric characters
|
19 |
+
return text
|
20 |
+
|
21 |
+
# Function to preprocess and generate summaries
|
22 |
+
def generate_summary(plot_synopsis):
|
23 |
+
# Preprocess the plot_synopsis
|
24 |
+
inputs = tokenizer("summarize: " + normalize_text(plot_synopsis),
|
25 |
+
max_length=3000, truncation=True, padding="max_length", return_tensors="pt")
|
26 |
+
inputs = inputs.to(device)
|
27 |
+
|
28 |
+
# Generate the summary
|
29 |
+
outputs = model.generate(inputs["input_ids"], max_length=315, min_length=20,
|
30 |
+
length_penalty=2.0, num_beams=4, early_stopping=True)
|
31 |
+
|
32 |
+
summary = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
33 |
+
return summary
|
34 |
+
|
35 |
+
# Gradio interface to take plot synopsis and output a generated summary
|
36 |
+
interface = gr.Interface(
|
37 |
+
fn=generate_summary,
|
38 |
+
inputs=gr.Textbox(label="Plot Synopsis", lines=10, placeholder="Enter the plot synopsis here..."),
|
39 |
+
outputs=gr.Textbox(label="Generated Summary"),
|
40 |
+
title="Plot Summary Generator",
|
41 |
+
description="This demo generates a plot summary based on the plot synopsis using a fine-tuned LED model."
|
42 |
+
)
|
43 |
+
|
44 |
+
# Launch the Gradio interface
|
45 |
+
interface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
torch
|
3 |
+
gradio
|
summary_generation_Led_4/config.json
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "/content/drive/MyDrive/summary_generation",
|
3 |
+
"activation_dropout": 0.0,
|
4 |
+
"activation_function": "gelu",
|
5 |
+
"architectures": [
|
6 |
+
"LEDForConditionalGeneration"
|
7 |
+
],
|
8 |
+
"attention_dropout": 0.0,
|
9 |
+
"attention_window": [
|
10 |
+
1024,
|
11 |
+
1024,
|
12 |
+
1024,
|
13 |
+
1024,
|
14 |
+
1024,
|
15 |
+
1024
|
16 |
+
],
|
17 |
+
"bos_token_id": 0,
|
18 |
+
"classif_dropout": 0.0,
|
19 |
+
"classifier_dropout": 0.0,
|
20 |
+
"d_model": 768,
|
21 |
+
"decoder_attention_heads": 12,
|
22 |
+
"decoder_ffn_dim": 3072,
|
23 |
+
"decoder_layerdrop": 0.0,
|
24 |
+
"decoder_layers": 6,
|
25 |
+
"decoder_start_token_id": 2,
|
26 |
+
"dropout": 0.1,
|
27 |
+
"encoder_attention_heads": 12,
|
28 |
+
"encoder_ffn_dim": 3072,
|
29 |
+
"encoder_layerdrop": 0.0,
|
30 |
+
"encoder_layers": 6,
|
31 |
+
"eos_token_id": 2,
|
32 |
+
"gradient_checkpointing": false,
|
33 |
+
"id2label": {
|
34 |
+
"0": "LABEL_0",
|
35 |
+
"1": "LABEL_1",
|
36 |
+
"2": "LABEL_2"
|
37 |
+
},
|
38 |
+
"init_std": 0.02,
|
39 |
+
"is_encoder_decoder": true,
|
40 |
+
"label2id": {
|
41 |
+
"LABEL_0": 0,
|
42 |
+
"LABEL_1": 1,
|
43 |
+
"LABEL_2": 2
|
44 |
+
},
|
45 |
+
"max_decoder_position_embeddings": 1024,
|
46 |
+
"max_encoder_position_embeddings": 16384,
|
47 |
+
"model_type": "led",
|
48 |
+
"num_hidden_layers": 6,
|
49 |
+
"pad_token_id": 1,
|
50 |
+
"torch_dtype": "float32",
|
51 |
+
"transformers_version": "4.42.4",
|
52 |
+
"use_cache": true,
|
53 |
+
"vocab_size": 50265
|
54 |
+
}
|
summary_generation_Led_4/generation_config.json
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_from_model_config": true,
|
3 |
+
"bos_token_id": 0,
|
4 |
+
"decoder_start_token_id": 2,
|
5 |
+
"eos_token_id": 2,
|
6 |
+
"pad_token_id": 1,
|
7 |
+
"transformers_version": "4.42.4"
|
8 |
+
}
|
summary_generation_Led_4/merges.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
summary_generation_Led_4/model.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d8f023dedaee3beff15d69b6dcf007839030bacdabc661fb606b7ad95d1dfc99
|
3 |
+
size 134
|
summary_generation_Led_4/special_tokens_map.json
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bos_token": {
|
3 |
+
"content": "<s>",
|
4 |
+
"lstrip": false,
|
5 |
+
"normalized": true,
|
6 |
+
"rstrip": false,
|
7 |
+
"single_word": false
|
8 |
+
},
|
9 |
+
"cls_token": {
|
10 |
+
"content": "<s>",
|
11 |
+
"lstrip": false,
|
12 |
+
"normalized": true,
|
13 |
+
"rstrip": false,
|
14 |
+
"single_word": false
|
15 |
+
},
|
16 |
+
"eos_token": {
|
17 |
+
"content": "</s>",
|
18 |
+
"lstrip": false,
|
19 |
+
"normalized": true,
|
20 |
+
"rstrip": false,
|
21 |
+
"single_word": false
|
22 |
+
},
|
23 |
+
"mask_token": {
|
24 |
+
"content": "<mask>",
|
25 |
+
"lstrip": true,
|
26 |
+
"normalized": true,
|
27 |
+
"rstrip": false,
|
28 |
+
"single_word": false
|
29 |
+
},
|
30 |
+
"pad_token": {
|
31 |
+
"content": "<pad>",
|
32 |
+
"lstrip": false,
|
33 |
+
"normalized": true,
|
34 |
+
"rstrip": false,
|
35 |
+
"single_word": false
|
36 |
+
},
|
37 |
+
"sep_token": {
|
38 |
+
"content": "</s>",
|
39 |
+
"lstrip": false,
|
40 |
+
"normalized": true,
|
41 |
+
"rstrip": false,
|
42 |
+
"single_word": false
|
43 |
+
},
|
44 |
+
"unk_token": {
|
45 |
+
"content": "<unk>",
|
46 |
+
"lstrip": false,
|
47 |
+
"normalized": true,
|
48 |
+
"rstrip": false,
|
49 |
+
"single_word": false
|
50 |
+
}
|
51 |
+
}
|
summary_generation_Led_4/tokenizer_config.json
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"add_prefix_space": false,
|
3 |
+
"added_tokens_decoder": {
|
4 |
+
"0": {
|
5 |
+
"content": "<s>",
|
6 |
+
"lstrip": false,
|
7 |
+
"normalized": true,
|
8 |
+
"rstrip": false,
|
9 |
+
"single_word": false,
|
10 |
+
"special": true
|
11 |
+
},
|
12 |
+
"1": {
|
13 |
+
"content": "<pad>",
|
14 |
+
"lstrip": false,
|
15 |
+
"normalized": true,
|
16 |
+
"rstrip": false,
|
17 |
+
"single_word": false,
|
18 |
+
"special": true
|
19 |
+
},
|
20 |
+
"2": {
|
21 |
+
"content": "</s>",
|
22 |
+
"lstrip": false,
|
23 |
+
"normalized": true,
|
24 |
+
"rstrip": false,
|
25 |
+
"single_word": false,
|
26 |
+
"special": true
|
27 |
+
},
|
28 |
+
"3": {
|
29 |
+
"content": "<unk>",
|
30 |
+
"lstrip": false,
|
31 |
+
"normalized": true,
|
32 |
+
"rstrip": false,
|
33 |
+
"single_word": false,
|
34 |
+
"special": true
|
35 |
+
},
|
36 |
+
"50264": {
|
37 |
+
"content": "<mask>",
|
38 |
+
"lstrip": true,
|
39 |
+
"normalized": true,
|
40 |
+
"rstrip": false,
|
41 |
+
"single_word": false,
|
42 |
+
"special": true
|
43 |
+
}
|
44 |
+
},
|
45 |
+
"bos_token": "<s>",
|
46 |
+
"clean_up_tokenization_spaces": true,
|
47 |
+
"cls_token": "<s>",
|
48 |
+
"eos_token": "</s>",
|
49 |
+
"errors": "replace",
|
50 |
+
"mask_token": "<mask>",
|
51 |
+
"model_max_length": 16384,
|
52 |
+
"pad_token": "<pad>",
|
53 |
+
"sep_token": "</s>",
|
54 |
+
"tokenizer_class": "LEDTokenizer",
|
55 |
+
"unk_token": "<unk>"
|
56 |
+
}
|
summary_generation_Led_4/training_args.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3e3addcd03e4df756227df87319ee2ce381285458b47ad8112d6bdb9baf62749
|
3 |
+
size 129
|
summary_generation_Led_4/vocab.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|