Spaces:
				
			
			
	
			
			
		Running
		
			on 
			
			T4
	
	
	
			
			
	
	
	
	
		
		
		Running
		
			on 
			
			T4
	Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | @@ -8,6 +8,10 @@ tokenizer = AutoTokenizer.from_pretrained("gpt2") | |
| 8 | 
             
            model = AutoModelForCausalLM.from_pretrained("gpt2")
         | 
| 9 |  | 
| 10 | 
             
            print("Loading finished.")
         | 
|  | |
|  | |
|  | |
|  | |
| 11 |  | 
| 12 | 
             
            print(f"Is CUDA available: {torch.cuda.is_available()}")
         | 
| 13 | 
             
            # True
         | 
| @@ -436,9 +440,6 @@ def get_beam_search_html( | |
| 436 | 
             
                    do_sample=False,
         | 
| 437 | 
             
                )
         | 
| 438 | 
             
                markdown = "The conclusive sequences are the ones that end in an `<|endoftext|>` token or at the end of generation."
         | 
| 439 | 
            -
                markdown += "\n\nThey are ranked by their scores, as given by the formula `score = cumulative_score / (output_length ** length_penalty)`.\n\n"
         | 
| 440 | 
            -
                markdown += "Only the top `num_beams` scoring sequences are returned: in the tree they are highlighted in **<span style='color:var(--secondary-500)!important'>blue</span>**."
         | 
| 441 | 
            -
                markdown += " The non-selected sequences are also shown in the tree, highlighted in **<span style='color:var(--primary-500)!important'>yellow</span>**."
         | 
| 442 | 
             
                markdown += "\n#### <span style='color:var(--secondary-500)!important'>Output sequences:</span>"
         | 
| 443 | 
             
                # Sequences are padded anyway so you can batch decode them
         | 
| 444 | 
             
                decoded_sequences = tokenizer.batch_decode(outputs.sequences)
         | 
| @@ -484,16 +485,13 @@ with gr.Blocks( | |
| 484 | 
             
                    value="Hugging Face is",
         | 
| 485 | 
             
                )
         | 
| 486 |  | 
| 487 | 
            -
             | 
| 488 | 
            -
                n_beams=1
         | 
| 489 | 
            -
                length_penalty=1
         | 
| 490 | 
            -
                num_return_sequences=3
         | 
| 491 | 
             
                button = gr.Button()
         | 
| 492 | 
             
                out_html = gr.Markdown()
         | 
| 493 | 
             
                out_markdown = gr.Markdown()
         | 
| 494 | 
             
                button.click(
         | 
| 495 | 
             
                    get_beam_search_html,
         | 
| 496 | 
            -
                    inputs=[text | 
| 497 | 
             
                    outputs=[out_html, out_markdown],
         | 
| 498 | 
             
                )
         | 
| 499 |  | 
|  | |
| 8 | 
             
            model = AutoModelForCausalLM.from_pretrained("gpt2")
         | 
| 9 |  | 
| 10 | 
             
            print("Loading finished.")
         | 
| 11 | 
            +
            n_steps=12
         | 
| 12 | 
            +
            n_beams=1
         | 
| 13 | 
            +
            length_penalty=1
         | 
| 14 | 
            +
            num_return_sequences=3
         | 
| 15 |  | 
| 16 | 
             
            print(f"Is CUDA available: {torch.cuda.is_available()}")
         | 
| 17 | 
             
            # True
         | 
|  | |
| 440 | 
             
                    do_sample=False,
         | 
| 441 | 
             
                )
         | 
| 442 | 
             
                markdown = "The conclusive sequences are the ones that end in an `<|endoftext|>` token or at the end of generation."
         | 
|  | |
|  | |
|  | |
| 443 | 
             
                markdown += "\n#### <span style='color:var(--secondary-500)!important'>Output sequences:</span>"
         | 
| 444 | 
             
                # Sequences are padded anyway so you can batch decode them
         | 
| 445 | 
             
                decoded_sequences = tokenizer.batch_decode(outputs.sequences)
         | 
|  | |
| 485 | 
             
                    value="Hugging Face is",
         | 
| 486 | 
             
                )
         | 
| 487 |  | 
| 488 | 
            +
               
         | 
|  | |
|  | |
|  | |
| 489 | 
             
                button = gr.Button()
         | 
| 490 | 
             
                out_html = gr.Markdown()
         | 
| 491 | 
             
                out_markdown = gr.Markdown()
         | 
| 492 | 
             
                button.click(
         | 
| 493 | 
             
                    get_beam_search_html,
         | 
| 494 | 
            +
                    inputs=[text],
         | 
| 495 | 
             
                    outputs=[out_html, out_markdown],
         | 
| 496 | 
             
                )
         | 
| 497 |  | 
 
			

