You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Text generation typically utilizes a greedy search algorithm that selects the word with the highest probability as the next word in the sequence. However, an alternative method called beam search can be used, which aims to minimize the possibility of overlooking hidden high probability word combinations. Beam search achieves this by retaining the num_beams most likely hypotheses at each step and ultimately selecting the hypothesis with the highest overall probability. We set `num_beams > 1` and `early_stopping=True` so that generation is finished when all beam hypotheses reached the EOS token.
638
+
639
+
```sql
640
+
SELECTpgml.transform(
641
+
task =>'{
642
+
"task" : "text-generation",
643
+
"model" : "gpt2-medium"
644
+
}'::JSONB,
645
+
inputs => ARRAY[
646
+
'Three Rings for the Elven-kings under the sky, Seven for the Dwarf-lords in their halls of stone'
647
+
],
648
+
args =>'{
649
+
"num_beams" : 5,
650
+
"early_stopping" : true
651
+
}'::JSONB
652
+
) AS answer;
653
+
```
654
+
655
+
*Result*
656
+
```json
657
+
[[
658
+
{"generated_text": "Three Rings for the Elven-kings under the sky, Seven for the Dwarf-lords in their halls of stone, Nine for the Dwarves in their caverns of ice, Ten for the Elves in their caverns of fire, Eleven for the"}
659
+
]]
660
+
```
661
+
Sampling methods involve selecting the next word or sequence of words at random from the set of possible candidates, weighted by their probabilities according to the language model. This can result in more diverse and creative text, as well as avoiding repetitive patterns. In its most basic form, sampling means randomly picking the next word $w_t$ according to its conditional probability distribution:
662
+
$$ w_t \approx P(w_t|w_{1:t-1})$$
663
+
664
+
665
+
However, the randomness of the sampling method can also result in less coherent or inconsistent text, depending on the quality of the model and the chosen sampling parameters such as temperature, top-k, or top-p. Therefore, choosing an appropriate sampling method and parameters is crucial for achieving the desired balance between creativity and coherence in generated text.
666
+
667
+
You can pass `do_sample = True` in the arguments to use sampling methods. It is recommended to alter `temperature` or `top_p` but not both.
668
+
669
+
*Temperature*
670
+
```sql
671
+
SELECTpgml.transform(
672
+
task =>'{
673
+
"task" : "text-generation",
674
+
"model" : "gpt2-medium"
675
+
}'::JSONB,
676
+
inputs => ARRAY[
677
+
'Three Rings for the Elven-kings under the sky, Seven for the Dwarf-lords in their halls of stone'
678
+
],
679
+
args =>'{
680
+
"do_sample" : true,
681
+
"temperature" : 0.9
682
+
}'::JSONB
683
+
) AS answer;
684
+
```
685
+
*Result*
686
+
```json
687
+
[[{"generated_text": "Three Rings for the Elven-kings under the sky, Seven for the Dwarf-lords in their halls of stone, and Thirteen for the Giants and Men of S.A.\n\nThe First Seven-Year Time-Traveling Trilogy is"}]]
688
+
```
689
+
*Top p*
690
+
691
+
```sql
692
+
SELECTpgml.transform(
693
+
task =>'{
694
+
"task" : "text-generation",
695
+
"model" : "gpt2-medium"
696
+
}'::JSONB,
697
+
inputs => ARRAY[
698
+
'Three Rings for the Elven-kings under the sky, Seven for the Dwarf-lords in their halls of stone'
699
+
],
700
+
args =>'{
701
+
"do_sample" : true,
702
+
"top_p" : 0.8
703
+
}'::JSONB
704
+
) AS answer;
705
+
```
706
+
*Result*
707
+
```json
708
+
[[{"generated_text": "Three Rings for the Elven-kings under the sky, Seven for the Dwarf-lords in their halls of stone, Four for the Elves of the forests and fields, and Three for the Dwarfs and their warriors.\" ―Lord Rohan [src"}]]
709
+
```
710
+
## Text-to-Text Generation
711
+
Text-to-text generation methods, such as T5, are neural network architectures designed to perform various natural language processing tasks, including summarization, translation, and question answering. T5 is a transformer-based architecture pre-trained on a large corpus of text data using denoising autoencoding. This pre-training process enables the model to learn general language patterns and relationships between different tasks, which can be fine-tuned for specific downstream tasks. During fine-tuning, the T5 model is trained on a task-specific dataset to learn how to perform the specific task.
0 commit comments