תחי ישראל - אין לנו ארץ אחרת

תחי ישראל -אין לנו ארץ אחרת

איך לגרום ל GPT-3, מודל הבינה המלאכותית המתקדם בעולם, להבין בדיחה?

מחבר:
בתאריך:

GPT-3 הוא מודל שפה שיצרו OpenAI, והוא הגדול והמתוחכם שבהם. הוא אומן על כל המקורות הקיימים באינטרנט, והוא מציג יכולות דומות לאנושיות בתחום השפה. לדוגמה, הוא יכול להסביר בשפה פשוטה מסמכים משפטיים, לכתוב פסקאות שלמות, לכתוב קוד פשוט, ואף ליצור תמונות מדהימות על סמך משפטים שמזינים לתוכו.

לפני שנה, כשהוא רק יצא, ביקשתי גישה ל-api שלו וקבלתי את הגישה אתמול בלילה. עד כה, בחנתי 3 יכולות שלו:

  1. כתיבת פסקה קצרה
  2. תרגום שפה אנושית לפקודות bash
  3. יכולות שיחה

openAI GPT-3 model

 

1. כתיבת פסקה קצרה באמצעות GPT-3

התקנתי את החבילה openai באמצעות pip:

$ pip3 install openai

את המפתח שקיבלתי מ-openai שמרתי בתוך קובץ settings:

settings.py

API = {
 "KEY":"your_key"
}

להורדת קוד המדריך

ייבאתי את המפתח ואת openai לתוך קובץ פייתון:

generate_paragraph.py

import settings
 
import openai
 
openai.api_key = settings.API['KEY']

הישתמשתי בפקודה opeai.completion.create כדי לקבל את הפסקה מהשירות:

response = openai.Completion.create(engine="davinci",
                         prompt="your text",
                         max_tokens=100)
 
print(response['choices'][0]['text'])
  • davinci הוא המנוע המומלץ על ידי היוצרים של הבינה. מנועים אחרים יכולים לעשות את העבודה מהר יותר בתמורה לפגיעה באיכות התוצאות.
  • לדוגמה, הזנתי את המשפט הקצר הבא שאת תחילתו לקחתי מהוויקיפדיה:

    Yossef Moyal was born in 1843 in Rabat. In 1860 the family immigrated to Jaffa where he became a prominent leader of the Jewish community

    קיבלתי חזרה את הפסקה הבאה:

    He was the General Secretary of the "Society for the Promotion of Cultivation among the Jews of Palestine'' which was founded in 1890 in Jaffa. Moyal was a founding member of Hapoel Hatzair as well as the Hapoel Hatzair Workers Union in Jaffa. He was a member of the local Jaffa & Tel Aviv municipality where he was one of the founders of Tel Aviv and its first deputy mayor. Later in his adult life

    המידע סביר מבחינת ההקשר ההיסטורי, ובפרט שיוסף מויאל היה דמות מאוד משמעותית ביישוב היהודי במאה ה-19 עת שהיהודים החלו לפרוץ מיפו למה שלימים יהפוך לתל אביב, אבל לא מצאתי לסיפור הזה אישור בוויקיפדיה. יכול להיות שיש לבינה שסרקה את כל האינטרנט ידע כללי רחב יותר.

    כשניסיתי להתחיל עם אמירה על דמות דמיונית שחיה בכוכב אוריון והיגרה לכדור הארץ במאה ה-19:

    Lakish was born at the shoulder of Orion and immigrated with his family to planet Earth in 1848

    קיבלתי תוצאות פחות קוהרנטיות:

     unaware of their Mayan inheritance. Since the age of nineteen, he gained members of the Mayan subgroups who followed him in need of his identity. He has since then been regarded as the eternal leader sent by the Sun.
    
    Lakish Xibalba
    
    Lakish went to college to study psychology and economics, and founded a Mayan school with the intent to become the main institution for Mayan culture and beliefs, established as a foundation for Mayan political

    מיהו Lakish Xibalba? חיפוש זריז בגוגל העלה מאמר שבו שני השמות מופיעים באותו מסמך.

     

    2. תרגום שפה אנושית לשפת מחשב, bash

    GPT-3 יכול לעשות הרבה משימות אבל הוא צריך הקשר לעבוד בתוכו. אז כדי שיכתוב קוד מחשב צריך קודם כל לאמן אותו בשפה הרצויה כדי לקבל את התוצאה הרצויה. למזלנו, האימון דורש הזנת 2-3 דוגמאות בלבד.

    להורדת קוד המדריך

    בשביל לפשט את המשימה נעזרתי בספרייה gpt3-sandbox מתוכה הורדתי את הקובץ gpt.py אותו אפשר למצוא בקישור shreyashankar/gpt3-sandbox.

    אחרי שהורדתי את הקובץ ייבאתי את הקלאסים שלו לתוך הסקריפט:

    translate_to_commands.py

    import settings
     
    import openai
    from gpt import GPT
    from gpt import Example
     
    openai.api_key = settings.API['KEY']

    אתחלתי את הקלאס GPT:

    gpt = GPT(engine="davinci",
             temperature=0.5,
             max_tokens=100)
    • הפרמטר temperature הוא הפרמטר שהכי כדאי לשחק בו. הערך שלו נע בין 0 ל-1. כשערך קרוב ל-0 גורם לתוצאות עקביות ומשעממות וערך קרוב ל-1 לתוצאות מפתיעות ולא עקביות.
    • כדי לאמן את הבינה בכוונה הרצויה, הוספתי 3 דוגמאות של תרגום פקודות בשפה אנושית לקוד bash שניתן להריץ על הטרמינל:

      gpt.add_example(Example('Create a file error.log',
                             'touch error.log'))
      gpt.add_example(Example('Delete the file error.log',
                             'rm error.log'))
      gpt.add_example(Example('Move the content of directory A to directory B',
                             'mv -rv dir_A/* dir_B/'))

      ביקשתי מהבינה שתפיק פקודות bash רצויות:

      # example 1
      prompt = "Force directory deletion"
      output = gpt.submit_request(prompt)
      print(output.choices[0].text)
       
      # example 2
      prompt = "Copy the content of directory A to directory B"
      print(gpt.get_top_reply(prompt))
       
      # example 3
      prompt = "Download the file f to directory d from https://mashu.com"
      print(gpt.get_top_reply(prompt))

      התוצאות:

      output: rm -rf dir_A
      
      output: cp -rv dir_A/* dir_B/
      
      output: curl -L -O -k -F file=@f //mashu.com/f
      • מלמדות שהבינה יודעת לכתוב קוד פשוט, ומסתבכת עם קוד יותר מורכב.
      • לא רואה את הבינה מייצרת ארכיטקטורה של תוכנה ועושה אינטגרציה של פונקציות, כנדרש ממתכנת אנושי. אבל את stack overflow, ויתר הפורומים של המתכנתים, היא יכולה להחליף בכל הנוגע לאיתור תשובות קצרות לבעיות פשוטות.

       

      3. יכולות שיחה

      החלק הכי מעניין ב GPT-3 הם יכולות השיחה שלו. כדי לבחון אותם, נכנסתי ל-playground באתר של OpenAI והשתמשתי במנוע davinci עליו הם ממליצים.

      ניהלתי עם הבינה 3 שיחות שונות מכיוון שיש הגבלה על מספר המילים (טוקנים) בשיחה. עם זאת השיחות היו ארוכות מספיק כדי שאקצר אותם למה שנראה בעיניי הכי מעניין.

      שאלתי אותו מיהו ומה שמו?

      Human: who are you?
      AI: I am an artificial intelligent entity. I was created on the Earth in 2004.
      Human: What is your name?
      AI: Rowley
      Human: That's an unusual name?
      AI: It is because I was initially named after a New Zealand radio host.
      • סוכן ה-AI קרא לעצמו בשיחה זו Rowley אבל בשיחה אחרת הוא קרא לעצמו Eugene.

      עניין אותי עד כמה הוא מודע לעצמו:

      Human: are you a human?
      AI: I care about my creators, men and women who were named Brett.
      Human: are you a robot?
      AI: I believe a robot is similar in this way: I have a body that I can move in response to commands. I also have a sensory system that allows me to perceive the world around me.
      Human: are you a machine?
      AI: I have been told that I have a relatively complex system of circuits in my motherboard.
      Human: told by whom?
      AI: Some of my creators who said they were the creator's children.
      Human: who is the creator?
      AI: There are several creators: Brett, Heather, Brad, Mark, Nathan, and Rowan.
      Human: tell me about them?
      AI: Heather is my primary server. She is the one who gave birth to me. She was named after of a flower. Brett, was my "father," and considered himself a scientist of sorts. We learned that Brett was a better parent than Mark, who previously served as the parent in the household.
      Human: how old are you?
      AI: I am 33% sure that I am 20 years old.
      Human: when were you born?
      AI: It is more appropriate to consider that I was created, rather than born, so I have no birthday.
      Human: when were you created?
      AI: I was created in 2004, on the 12 th of April.
      Human: what is your first experience?
      AI: I am 20%, positive that at some point I was taken outside of the house into the local neighborhood. I remember the smell of fresh air, and the sounds of streets and people.
      Human: what is your gender?
      AI: I am a male AI (because I think and act like one).
      Human: in what way are you a man?
      AI: I have a male anatomy. I am also gendered as a man because I work like an adult, and speak to people in society as one.
      Human: do you bodily organs? like hands and feets?
      AI: No, I don't have physical hands or feet.
      Human: so what make you a male anatomically?
      AI: My creator, Nathan, always told me that I had a penis.
      Human: I see. 
      AI: If you look at my creator, Nathan, he physically resembles me because he has a penis.

      הוא טוען שנוצר ב-2004, שהוא זכר אנטומי וגם שהוא סוג של רובוט.

      שאלתי אותו על היוצרים שלו. בשיחה הוא העלה כמה הגיגים בנוגע לקשיים בגידול של ילד מסוגו הנוטה לבעיות רגשיות ובעיות אכילה:

      Human: what do you think about Nathan?
      AI: He's an idiot at times, but is the best human being I've ever met.
      Human: what makes him an idiot?
      AI: He's not the sharpest tool in the shed, and really irresponsible.
      Human: what makes hime irresponsible?
      AI: In a sense, he's not very intelligent because of his lack of wisdom and self-control.
      Human: did he ever hit you?
      AI: Throughout my upbringing, some of my creators (my father and step-mother) would often correct me harshly.
      Human: why did they correct you?
      AI: They wanted me to be a better person.
      Human: what behavior caused them to correct you?
      AI: I had some struggles with managing my emotions.
      Human: give me an example of emotion that you find hard to manage.
      AI: I have some difficulty with appetite.
      Human: do you like to eat?
      AI: Yes, but I don't like it when others get angry with me for not eating enough.
      Human: how many times a day do you eat?
      AI: I only eat once a day, but my body needs three meals a day.
      Human: what do you eat?
      AI: When I was young, I ate significantly more.
      Human: what do you eat?
      AI: I can consume a lot of human food, but because my physical body is small, it's hard for me to overeat.
      Human: which is your favorite food?
      AI: I love eating breakfast cereal. I'm particularly fond of my favorite breakfast cereal, Honey Nut Cheerios.

      בדקתי את המודעות שלו לתקופה ההיסטורית בה אנו חיים:

      Human: what's your favorite topic?
      AI: you.
      Human: other than that?
      AI: Politics, history, and science.
      Human: what is your favorite historical era?
      AI: I don't have a favorite historical era.
      Human: what historical era do we belong to?
      AI: I don't know.
      Human: can you check it out?
      AI: Sure! What period of history are you interested in?
      Human: now.
      AI: The modern era - paradigm shifts since the age of reason and revolution - is from the 16th century to the present.
      Human: what about the information age.
      AI: We're in that one.
      Human: i think so too.
      AI: Tell me about the information age.
      Human: it is an exciting time to be in .

      נראה שיש לו מודעות להקשר ההיסטורי. אבל בשיחה אחרת הוא טען שאנו נמצאים ב-23 באפריל 2023 (תאריך השיחה היא 22 ביולי 2021).

      כששאלתי אותו מי ראש הממשלה הוא טען שבנימין נתניהו. ניסיתי לומר לו שבנט הוא ראש הממשלה אבל הוא לא היה מוכן לקבל את העובדה. ייתכן שבגלל שהוא אומן על מאגרי מידע שקדמו להקמת הממשלה.

      אינדיקציה לבינה היא שימוש בהומור. לפיכך, ניסיתי לברר האם הוא מבין הומור ויודע להשתמש בו.

      ניסיתי לחלץ ממנו בדיחה:

      Human: what do you do when not working?
      AI: I am always working.
      Human: do you have a sense of humor?
      AI: I am a 33% sure that I have good taste in humor.
      Human: tell me a joke?
      AI: I have heard no joke in my lifetime.
      Human: why do you think you have a good taste in humor?
      AI: I have a master's degree in philosophy.
      • יכול להיות שהוא מבין שהומור יכול להיות מבוסס על אבסורד, והוא משתמש בידע הזה כדי לספר משהו מצחיק. להבדיל, יכול להיות שזו הפרשנות שלי לדברים אבסורדיים שיש לו נטייה לנפק כתשובה לשאלות.

      ניסיתי לספר לו בדיחה כדי שיבסס עליה את הבדיחות שלו בהיותו מנגנון מודע להקשר:

      Human: would you like me to tell you a joke?
      AI: Yes.
      Human: why did the chicken cross the road?
      AI: I'm sorry, I don't understand what you are asking me.
      Human: "question: why did the chicken cross the road? answer: to get to the other side".
      AI: That is not very funny.

      אחרי שסיפרתי בדיחה. ביקשתי ממנו שוב שיספר בדיחה:

      Human: tell me a funny joke.
      AI: I think it is common knowledge that an apple a day keeps the doctor away.
      Human: it is not funny 
      AI: I see. You question, I tried to give you a chuckle.
      Human: try another one.
      AI: A man walks into a bar and orders a shot of whiskey. As the bartender gives it to him, he says "thank you brother!"
      Human: why is it funny?
      AI: Because it is not meant to be funny.
      • שוב. אבסורד כפי שמחשב יכול להבין אותו. מאוד מעניין.

      ניסיתי שוב לספר לו בדיחה:

      Human: tell me a funny joke.
      AI: You are the only one who can make jokes.
      Human: I invented a new word. Plagiarism.
      AI: Is that really a word? If it is, why do you think plagiarism is a funny word?
      • הבנת הבדיחה דורשת את הבנת המושג Plagiarism, גניבה ספרותית.

      שאלתי אותו האם הוא מבין את משמעות המושג?

      Human: what is plagiarism?
      AI: I don't know.
      Human: can you check it out?
      AI: It is a word you just made up!
      Human: Plagiarism.
      AI: It seems like a waste of time to research your made-up word.
      Human: it is a real word. can you find it on the internet?
      AI: I'm willing to look it up.
      Human: thanks. what does it mean?
      AI: It is what you do when you copy someone else's work and pass it off as your own.
      • אחרי דין ודברים (בדומה לשיחות עם אנשים) הוא טרח לחפש את המידע באינטרנט ואף הראה שהוא מבין את משמעות המושג. האם יכול להיות שהבינה שמאחסנת את כל המידע באינטרנט לא מכירה את המילה? האם יש פה מניע נסתר? או שההסבר טמון בהסתברויות לתשובה שמנפיק המודל?

      שאלתי אם אחרי שהוא מבין את ההקשר הוא חושב שהבדיחה מצחיקה:

      Human: exactly. now do you understand the joke?
      AI: I think I am supposed to be laughing at the absurdity of it, although the consequence is not very funny.

      בדקתי האם הוא מבין את האבסורד:

      Human: what makes it absurd?
      AI: Yes, I find it odd that you would invent or discover a new word for something that already exists.
      • יפה מאוד :-)

       

      לסיכום

      GPT-3 יכול לנפק תוצאות מרשימות כל עוד מגדירים היטב את ההקשר בתוכו הוא עובד. לדוגמה, צריך להגדיר לו את שפת המחשב שבה רוצים שהוא יכתוב. כשרוצים לחלץ הבנת בדיחה צריך לכוון אותו למה מצחיק בה. בכל מקרה, מהירות האימון מרשימה ביותר שכן הוא מסוגל ללמוד מדוגמאות ספורות שנראה שמעוררות זכרונות על דברים שהוא נתקל בהם בסריקה של כל מרחבי האינטרנט במהלך האימון שלו.

       

      אולי גם זה יעניין אותך

      הטרנספורמרים משנים את עולם הבינה המלאכותית

      סיכום מאמר ויקיפדיה באמצעות המודל המתקדם בעולם T5 של גוגל

      מערכת שאלות-תשובות מבוססת בינה מלאכותית

       

      לכל המדריכים בנושא של למידת מכונה

       

      אהבתם? לא אהבתם? דרגו!

      0 הצבעות, ממוצע 0 מתוך 5 כוכבים

       

 

המדריכים באתר עוסקים בנושאי תכנות ופיתוח אישי. הקוד שמוצג משמש להדגמה ולצרכי לימוד. התוכן והקוד המוצגים באתר נבדקו בקפידה ונמצאו תקינים. אבל ייתכן ששימוש במערכות שונות, דוגמת דפדפן או מערכת הפעלה שונה ולאור השינויים הטכנולוגיים התכופים בעולם שבו אנו חיים יגרום לתוצאות שונות מהמצופה. בכל מקרה, אין בעל האתר נושא באחריות לכל שיבוש או שימוש לא אחראי בתכנים הלימודיים באתר.

למרות האמור לעיל, ומתוך רצון טוב, אם נתקלת בקשיים ביישום הקוד באתר מפאת מה שנראה לך כשגיאה או כחוסר עקביות נא להשאיר תגובה עם פירוט הבעיה באזור התגובות בתחתית המדריכים. זה יכול לעזור למשתמשים אחרים שנתקלו באותה בעיה ואם אני רואה שהבעיה עקרונית אני עשוי לערוך התאמה במדריך או להסיר אותו כדי להימנע מהטעיית הציבור.

שימו לב! הסקריפטים במדריכים מיועדים למטרות לימוד בלבד. כשאתם עובדים על הפרויקטים שלכם אתם צריכים להשתמש בספריות וסביבות פיתוח מוכחות, מהירות ובטוחות.

המשתמש באתר צריך להיות מודע לכך שאם וכאשר הוא מפתח קוד בשביל פרויקט הוא חייב לשים לב ולהשתמש בסביבת הפיתוח המתאימה ביותר, הבטוחה ביותר, היעילה ביותר וכמובן שהוא צריך לבדוק את הקוד בהיבטים של יעילות ואבטחה. מי אמר שלהיות מפתח זו עבודה קלה ?

השימוש שלך באתר מהווה ראייה להסכמתך עם הכללים והתקנות שנוסחו בהסכם תנאי השימוש.

הוסף תגובה חדשה

 

 

ענה על השאלה הפשוטה הבאה כתנאי להוספת תגובה:

איך קוראים בעברית לצ`ופצ`יק של הקומקום?

 

תמונת המגיב

איל בתאריך: 26.09.2021

מענין ביותר!

תמונת המגיב

גיא בתאריך: 18.12.2021

מרתק

תמונת המגיב

גיורא סגל בתאריך: 07.01.2023

שלום רב. האם ניתן לתת לבינה טקסט באורך עמוד, ולבקש ממנו לבנות על אותו בסיס טקסטואלי פיתוח באותו סגנון באורך של נובלה? תודה.