markscrivo commited on
Commit
1589d39
1 Parent(s): 7d1810a

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -36
app.py DELETED
@@ -1,36 +0,0 @@
1
- import jax
2
- import jax.numpy as jnp
3
- from transformers import FlaxBigBirdForQuestionAnswering, BigBirdTokenizerFast
4
- import gradio as gr
5
-
6
- FLAX_MODEL_ID = "vasudevgupta/flax-bigbird-natural-questions"
7
-
8
- if __name__ == "__main__":
9
- model = FlaxBigBirdForQuestionAnswering.from_pretrained(FLAX_MODEL_ID, block_size=64, num_random_blocks=3)
10
- tokenizer = BigBirdTokenizerFast.from_pretrained(FLAX_MODEL_ID)
11
-
12
- @jax.jit
13
- def forward(*args, **kwargs):
14
- return model(*args, **kwargs)
15
-
16
- def get_answer(question, context):
17
-
18
- encoding = tokenizer(question, context, return_tensors="jax", max_length=512, padding="max_length", truncation=True)
19
- start_scores, end_scores = forward(**encoding).to_tuple()
20
-
21
- # Let's take the most likely token using `argmax` and retrieve the answer
22
- all_tokens = tokenizer.convert_ids_to_tokens(encoding["input_ids"][0].tolist())
23
-
24
- answer_tokens = all_tokens[jnp.argmax(start_scores): jnp.argmax(end_scores)+1]
25
- answer = tokenizer.decode(tokenizer.convert_tokens_to_ids(answer_tokens))
26
-
27
- return answer
28
-
29
- default_context = "Models like BERT, RoBERTa have a token limit of 512. But BigBird supports up to 4096 tokens! How does it do that? How can transformers be applied to longer sequences? In Abhishek Thakur's next Talks, I will discuss BigBird!! Attend this Friday, 9:30 PM IST Live link: https://www.youtube.com/watch?v=G22vNvHmHQ0.\nBigBird is a transformer based model which can process long sequences (upto 4096) very efficiently. RoBERTa variant of BigBird has shown outstanding results on long document question answering."
30
- question = gr.inputs.Textbox(lines=2, default="When is talk happening?", label="Question")
31
- context = gr.inputs.Textbox(lines=10, default=default_context, label="Context")
32
-
33
- title = "BigBird-RoBERTa"
34
- desc = "BigBird is a transformer based model which can process long sequences (upto 4096) very efficiently. RoBERTa variant of BigBird has shown outstanding results on long document question answering."
35
-
36
- gr.Interface(fn=get_answer, inputs=[question, context], outputs="text", title=title, description=desc).launch()