LLM

Large Language Model
GPT-2 is so small that we can run it in a local machine, it is available at Wolfram NN repo:
In[]:=
llm=NetModel[{"GPT2 Transformer Trained on WebText Data","Task"->"LanguageModeling"}]
Out[]=
NetChain
Input
string
vector of n indices (range: 1..50257)
embedding
NetGraph (4 nodes) ↗
matrix(size: n×768)
decoder
NetChain (13 nodes)
matrix(size: n×768)
last
SequenceLastLayer
vector(size: 768)
classifier
LinearLayer ↗
vector(size: 50257)
probabilities
SoftmaxLayer
vector(size: 50257)
Output
class
Data not saved. Save now

We can try to guess the next text token:
In[]:=
llm["Gosto de esportes radicais porque"]
Out[]=
es
We can check the 15 best possibilities for the next sentence word (token) LLM style:
llm["At harvard I am going to study",{"TopProbabilities",15}]​​%//Column​​PieChart[Values[%%],ChartLabels->Keys[%%]]​​
Now in a LOOP... we can try to complete the sentences by the next 20 tokens:
In[]:=
generateSample[languagemodel_][input_String,numTokens_:10,temperature_:1]:=Nest[Function[StringJoin[#,llm[#,{"RandomSample","Temperature"->temperature}]]],input,numTokens];
In[]:=
generateSample[llm]["Albert Einstein was a German-born theoretical physicist",20]
Out[]=
Albert Einstein was a German-born theoretical physicist, with close records in physics and his institute of physics was the German Foundation for Archival Research,
In[]:=
generateSample[llm]["Sonia Braga é uma atriz brasileira famosa por",20]
Out[]=
Sonia Braga é uma atriz brasileira famosa por contease de ses innisateurs : verísquina informazione prrigava

The Next Word...

Getting another model we can run locally in our PC:
In[]:=
llm2=NetModel[{"GPT Transformer Trained on BookCorpus Data","Task"->"LanguageModeling"}]
Out[]=
NetChain
Input
string
vector of n indices (range: 1..40478)
embedding
NetGraph (5 nodes) ↗
matrix(size: n×768)
decoder
NetChain (12 nodes)
matrix(size: n×768)
last
SequenceLastLayer
vector(size: 768)
classifier
LinearLayer ↗
vector(size: 40478)
probabilities
SoftmaxLayer
vector(size: 40478)
Output
class
Data not saved. Save now

In[]:=
Information[llm2]
Out[]=
Net Information
Layers Count
860
Arrays Count
986
Shared Arrays Count
1
Input Port Names
{Input}
Output Port Names
{Output}
Arrays Total Element Count
116534784
Arrays Total Size
466.139
MB
We can again try to guess the next word (token):
In[]:=
llm2["I never gonna let you "]
Out[]=
go
In[]:=
llm2["You say, Yes, I say, No. You say, Stop and I say, "]
Out[]=
stop
In[]:=
llm2["The book is on the "]
Out[]=
table
In[]:=
llm2["Where have you "]
Out[]=
been
In[]:=
llm2["Scooby Dooby "]
Out[]=
.
In[]:=
llm2["Be or not to be this is the "]
Out[]=
same
In[]:=
llm2["At the grossery store I buy "]
Out[]=
a

OpenAI API integration

The newer algorithms GPT-3.5 and GPT-4 that run on the cloud because they are giant (Big data) and can’t run on our local PC, we have better results.
How can I start using chat notebooks in Wolfram products?
​https://support.wolfram.com/62525
LLM-Related Functionality
​https://reference.wolfram.com/language/guide/LLMFunctions.html
The Wolfram Prompt Repository
​https://resources.wolframcloud.com/PromptRepository/
In[]:=
LLMResourceFunction["Emojify"]["For what shall it profit a man, if he shall gain the whole world, and lose his own soul?"]
Out[]=
For what shall it profit a man, if he shall gain the 🌍, and lose his own 😇?
In[]:=
LLMSynthesize[{LLMPrompt["PoemVersion"],LLMPrompt["Emojify"]["Roses are red, violets are blue."]}]
Out[]=
In colors splendid, nature's true delight,Roses bloom and violets shine so bright.🌹🌺🌹🌺​With petals gentle, crimson and pure,A love story written, love that endures.❤️💑💞​As dawn's light breaks, on a new day's morn,Blooming roses, a beauty finely born.🌅🌹🌷🌞​And violets, lovely as the twilight sky,Together, they paint a heartfelt lullaby.🌃🌹🌸🎶​Love's symphony, harmonious and grand,In every petal, emotions understand.💞🎵🌹​While roses whisper secrets, love's embrace,Violets add their charm with gentle grace.🌹💬💕🌸​Their vibrant hues, emotions softly speak,Of passion, affection, love pure and meek.❣️🎨💬😌​So let these flowers, in verse, portray,Love's magic, that forever may stay.🌹🌸✍️💖
Those cloud integration to OpenAI APIs brings synthesis algorithms for images too:
CHAT NOTEBOOKS
You can use those chat notebooks on Mathematica client for Mac, Windows or Linux:
File ▶ New ▶ Chat–Enabled Notebook
File ▶ New ▶ Chat–Driven Notebook

ChatGPT Plus: Wolfram Plugin

Those are resources from OpenAI, not from Wolfram, but integrated with Wolfram tech.
◼
  • Open - GPT-3 (Gratuito - free)
  • ◼
  • ChatGPT Plus - Browser - GPT-4 (US$ 20.00 ao mês pago anualmente - monthly price paid annually)
  • ◼
  • API (Pré-pago, cobrança por token) - Prazo de teste...
  • ​
    AI technology has been super fashionable these last few months. Wolfram AI technology has been a reality for a long time.
    ​
    For subscribers of OpenAI’s ChatGPT Plus ($20.00 month), the Wolfram plugin is available, with access to accurate data from Wolfram Alpha, code generation in Wolfram Language. ChatGPT is very bad at calculation, now the problem is solved. Furthermore, ChatGPT does not have updated data, it works with previously trained data. Now he has access to updated data on weather, stocks, maps, elevation, flights, countries, history, etc... In addition to sophisticated algorithms including ML and AI. Top virtual assistants make calls to Wolfram “behind the scenes” and now ChatCPT does too.
    ​
    ChatGPT Gets Its “Wolfram Superpowers”!
    ​https://writings.stephenwolfram.com/2023/03/chatgpt-gets-its-wolfram-superpowers/​
    ​
    Cooking recipes with GPT-3, Dall-e and the Wolfram Language
    ​https://community.wolfram.com/groups/-/m/t/2848741​
    ​
    For GPT-3.5 and GPT-4 we have integration with the OpenAI API in the cloud with a Packet, in this case you need an OpenAI key for your access:
    ​https://resources.wolframcloud.com/PacletRepository/resources/ChristopherWolfram/OpenAILink/

    GPT-4 Training

    Training cost US$ 4M to US$ 6M
    4 Weeks at the cloud to process
    ​
    Big Data from:
    ​
    - WEB (HTML, TXT, etc...)
    - Wikipedia
    - Reddit (mídia sócial)
    - Books digitalized​
    ​
    Bloomberg: Did training on your knowledge base - BloombergGPT: A Large Language Model for Finance
    ​https://www.bloomberg.com/company/press/bloomberggpt-50-billion-parameter-llm-tuned-finance/​
    ​
    Big techs can handle that! To train, maintain and process LLMs. Other companies will consume WEB API to integrate it with their systems, data and knowledgebase.

    AI Hype

    https://the-decoder.com/bloomberggpt-is-a-gpt-3-level-language-model-for-the-financial-industry/
    https://www.datakeen.co/what-is-artificial-intelligence-2/
    https://swisscognitive.ch/2020/12/18/narrow-ai/
    https://www.gartner.com.br/pt-br/artigos/novidades-no-gartner-hype-cycle-for-emerging-technologies-de-2022
    To learn more

    References

    ◼
  • https://www.wolfram.com/
  • ◼
  • https://www.wolframalpha.com/
  • ◼
  • https://www.wolframcloud.com/
  • ◼
  • https://www.wolfram.com/wolfram-u/
  • ◼
  • https://www.wolfram.com/notebooks/
  • ◼
  • https://reference.wolfram.com/language/
  • ◼
  • https://blog.wolfram.com/
  • Online Books

    ◼
  • An Elementary Introduction to the Wolfram Language
    ​https://www.wolfram.com/language/elementary-introduction/2nd-ed/
  • ◼
  • Introduction to Machine Learning
    ​https://www.wolfram.com/language/introduction-machine-learning/
  • ◼
  • What Is ChatGPT Doing … and Why Does It Work?
    ​https://writings.stephenwolfram.com/2023/02/what-is-chatgpt-doing-and-why-does-it-work/
  • ◼
  • Query: Getting information from data with the Wolfram Language
    ​https://www.wolfram.com/language/query-getting-information-from-data-with-the-wolfram-language/
  • Explore...

    Wolfram Language & System - Documentation Center
    ​https://reference.wolfram.com/language/
    Wolfram Language: INTRODUÇÃO RÁPIDA PARA PROGRAMADORES
    ​https://www.wolfram.com/language/fast-introduction-for-programmers/pt-br/?source=footer
    Mathematica e Wolfram Language INTRODUÇÃO RÁPIDA PARA ESTUDANTES DE MATEMÁTICA
    ​https://www.wolfram.com/language/fast-introduction-for-math-students/pt-br/?source=footer
    How to | Work with Lists
    ​https://reference.wolfram.com/language/howto/WorkWithLists.html
    Functional Programming
    ​https://reference.wolfram.com/language/guide/FunctionalProgramming.html
    Wolfram University
    ​https://www.wolfram.com/wolfram-u/
    Wolfram Language page
    ​https://www.wolfram.com/language/

    Wolfram Language hands on at Wolfram Cloud
    ​
    NOW!

    www.wolframcloud.com​
    ​
    - Numerical Computation
    ​https://www.conradwolfram.com/writings/covid19-excel07​
    https://floating-point-gui.de/
    ​
    - Expressions
    ​https://reference.wolfram.com/language/tutorial/Expressions.html#4715​
    ​https://reference.wolfram.com/language/guide/Expressions.html​
    ​
    - Symbolic Computation
    ​https://reference.wolfram.com/language/tutorial/SymbolicCalculations.html​
    ​https://reference.wolfram.com/language/tutorial/AlgebraicCalculations.html#29942​
    ​
    - Functional Programming
    ​https://reference.wolfram.com/language/tutorial/FunctionalOperations.html#17469​
    ​https://reference.wolfram.com/language/guide/FunctionalProgramming.html

    Final Thoughts

    AI is here to stay!
    There is a hype!
    Lots of possibilities!
    Academia and big techs heading the field!
    ◼
  • Experiment - CODE
  • ◼
  • Read & Learn
  • ◼
  • Share - Community
  • ◼
  • Turn your idea into a startup and generate value
  • ◼
  • Surf this wave
  • Wolfram Summer School

    Wolfram Summer School
    ​
    Explore and create projects at the frontiers of science, technology and innovation
    ​https://education.wolfram.com/summer-school

    CITE THESE NOTEBOOKS

    Warm-up workshop: Foundations of Wolfram Language, IA, ML, and LLMs​
    by Daniel Carvalho​
    Wolfram Community, STAFF PICKS, November 9, 2023
    ​https://community.wolfram.com/groups/-/m/t/3062527