Showing posts with label learning. Show all posts
Showing posts with label learning. Show all posts

Tuesday, December 27, 2022

Discover Natural Language Processing with the help of ChatGPT

The latest generation of machine learning is of magical education value:

  • They can "show you that something is possible".
  • They are quick: New concepts can be explored in seconds.
  • They are very powerful.
Best to show by example. This post-Xmas 2022 week I am refreshening my natural language processing skills. Therefore I start my learning sessions with the following request:

Can you tell me the little red riding hood story while including the phrase structure name and the most important phrase structure properties of each phrase structure of the story.

https://chat.openai.com/chat responds with: 

Sure! Here is the story of Little Red Riding Hood, with the phrase structure name and the most important phrase structure properties included for each phrase structure:
Once upon a time, there was a little girl (noun phrase) who lived in a village (noun phrase) near the forest (noun phrase). She had a red hooded cloak (noun phrase), which she always wore (verb phrase, finite, past tense) on her daily walks (noun phrase) to visit her grandmother (noun phrase) who lived on the other side of the forest (prepositional phrase, place).
One day, her mother (noun phrase) said (verb phrase, finite, past tense) to her (verb phrase, finite, past tense, indirect object), "Take (verb phrase, imperative mood) this basket (noun phrase) of goodies (noun phrase) to your grandmother (verb phrase, finite, present tense, indirect object). She is not feeling well (adjective phrase) today (adverb phrase, time)."
The little girl (noun phrase) set off (verb phrase, finite, past tense) through the forest (prepositional phrase, place), and on the way (adverb phrase, time), she encountered (verb phrase, finite, past tense) a wolf (noun phrase). "Where (adverb phrase) are you going (verb phrase, present tense), little girl (verb phrase, present tense, direct object)?" the wolf (noun phrase) asked (verb phrase, finite, past tense)...

I cannot remember what are the typical phrase properties. So I ask, and get the following phrase structure properties:

  • Head: the central word or group of words in a phrase that gives the phrase its main meaning
  • Modifier: a word or group of words that provides additional information about the head of a phrase
  • Function: the grammatical role that a phrase plays in a sentence
  • Complementation: the addition of a complement (a word or group of words that is necessary to complete the meaning of a verb) to a verb phrase
  • Dependency: the relationship between one phrase and another, in which one phrase relies on or depends on the other for its meaning
  • Voice: the form of a verb that indicates whether the subject of the verb is performing the action or is the recipient of the action
  • Tense: the form of a verb that indicates the time when the action described by the verb takes place
  • Mood: the form of a verb that indicates the attitude or mode of the speaker or writer toward the action described by the verb
  • Finiteness: the property of a verb phrase that indicates whether it is complete or incomplete
  • Agreement: the correspondence in number, person, or gender between the subject and verb of a sentence
  • Person: the form of a verb that indicates the perspective of the speaker or writer (first person, second person, or third person)
  • Number: the form of a verb or pronoun that indicates whether it refers to one or more than one person or thing
  • Gender: the form of a pronoun or noun that indicates whether it refers to a male or female
  • Case: the form of a noun or pronoun that indicates its grammatical function in a sentence (subject, object, possessive, etc.)
  • Aspect: the form of a verb that indicates the extent or completeness of the action described by the verb
  • Formality: the level of politeness or formality in the language used
  • Emphasis: the focus or emphasis given to a particular word or phrase in a sentence
  • Syntactic role: the function of a phrase in the sentence
  • Negation: the presence or absence of a word or phrase that indicates the opposite or negation of the action of the verb
  • Emotion: the expression of feelings or emotions in the language used
  • Quantity: the amount or quantity of something mentioned in the phrase
  • Quality: the characteristic or quality of something mentioned in the phrase
  • Condition: the state or condition of something mentioned in the phrase
  • Reason: the cause or reason for something mentioned in the phrase
  • Manner: the way in which something is done or happens mentioned in the phrase
  • Place: the location or place where something is or happens mentioned in the phrase
  • Time: the point in time when something is or happens mentioned in the phrase
  • Comparison: the comparison of one thing to another mentioned in the phrase
  • Possession: the ownership or possession of something mentioned in the phrase
  • Purpose: the intended or desired result or purpose of something mentioned in the phrase
I then do the same for the phrase structures. Here is a descriptions and their major properties of the first major fifteen:
  1. Noun phrase: a phrase that functions as a noun in a sentence and consists of a head noun and any modifiers. Major properties: head, modifier, function, agreement (person, number, gender, case).
  2. Adjective phrase: a phrase that functions as an adjective in a sentence and consists of an adjective as the head and any modifiers. Major properties: head, modifier, function
  3. Adverb phrase: a phrase that functions as an adverb in a sentence and consists of an adverb as the head and any modifiers. Major properties: head, modifier, function.
  4. Verb phrase: a phrase that consists of a verb and any modifiers or complements and functions as the predicate of a sentence. Major properties: head, modifier, complementation, function, tense, mood, finiteness, agreement (person, number).
  5. Prepositional phrase: a phrase that consists of a preposition, its object (a noun or pronoun), and any modifiers of the object, and functions as an adjective or adverb in a sentence. Major properties: head, object, modifier, function.
  6. Infinitive phrase: a phrase that consists of an infinitive (the base form of a verb preceded by "to") and any modifiers or complements and functions as a noun, adjective, or adverb in a sentence. Major properties: head, modifier, complementation, function.
  7. Gerund phrase: a phrase that consists of a gerund (a verb form ending in "-ing" that functions as a noun) and any modifiers or complements and functions as a subject, direct object, subject complement, or object of a preposition in a sentence. Major properties: head, modifier, complementation, function.
  8. Participle phrase: a phrase that consists of a participle (a verb form ending in "-ing," "-ed," or "-en" that functions as an adjective) and any modifiers and functions as an adjective in a sentence. Major properties: head, modifier, function.
  9. Appositive phrase: a noun or noun phrase that renames or explains another noun or noun phrase, and is set off by commas or parentheses. Major properties: head, modifier, function.
  10. Absolute phrase: a noun phrase, participle phrase, or adjective phrase that modifies the whole sentence, and is not directly connected to the rest of the sentence. Major properties: head, modifier, function.
  11. Participial phrase: a phrase that consists of a participle and any modifiers and functions as an adjective in a sentence. Major properties: head, modifier, function.
  12. Prepositional object phrase: a phrase that consists of a noun or pronoun and any modifiers and functions as the object of a preposition. Major properties: head, modifier, function.
  13. Subject complement phrase: a phrase that follows a linking verb and complements the subject of the sentence by renaming or describing it. Major properties: head, modifier, function.
  14. Object complement phrase: a phrase that follows a direct object and complements it by renaming or describing it. Major properties: head, modifier, function.
  15. Adverbial phrase: a phrase that functions as an adverb in a sentence and consists of an adverb as the head and any modifiers. Major properties: head, modifier, function.
For inspiration, I ask for an ascii text representation. (I bet that using ASCII is not very modern!). Which produces:

Once upon a time | noun phrase | there was | verb phrase / \ finite past / \ a little girl / | \ | \ a an the little | | noun noun | | who who / | \ | \ lived in a village | | | noun noun noun | | | near the near | | noun noun | forest | noun | she | noun | had | verb | a | noun | red | adjective | hooded | adjective | cloak | noun

                                             ... 

Then I ask for a Prolog representation:

% Characters
character(little_red_riding_hood).
character(wolf).
character(grandmother).

% Relationships
relationship(little_red_riding_hood, grandmother, granddaughter).

% Locations
location(forest).
location(path).
location(grandmother's_house).

% Actions
action(little_red_riding_hood, start_journey, forest).
action(little_red_riding_hood, go_through, path).
action(little_red_riding_hood, arrive_at, grandmother's_house).
action(wolf, start_journey, forest).
action(wolf, go_through, path).
action(wolf, arrive_at, grandmother's_house).
action(wolf, disguise_as, grandmother).
action(wolf, eat, grandmother).

% Items
item(basket).
item(cake).
item(wine).

% Facts
has(little_red_riding_hood, basket).
contains(basket, cake).
contains(basket, wine).
A which point I noted that this is the 'fabric' of the little red riding hood story, but much is missing. So I ask the machine learning to produce an alternative Prolog version that captures an object centric view and the emotional tension of the story. Which it produce promptly!
% Objects
object(little_red_riding_hood).
object(wolf).
object(grandmother).
object(basket).
object(cake).
object(wine).
object(forest).
object(path).
object(grandmother's_house).

% Object properties
property(little_red_riding_hood, human).
property(wolf, animal).
property(grandmother, human).
property(basket, container).
property(cake, food).
property(wine, drink).
property(forest, nature).
property(path, nature).
property(grandmother's_house, building).

% Object relationships
relationship(little_red_riding_hood, has, basket).
contains(basket, cake).
contains(basket, wine).

% Emotional tension
emotion(little_red_riding_hood, excited, start_journey).
emotion(little_red_riding_hood, worried, arrive_at_grandmother's_house).
emotion(wolf, hungry, start_journey).
emotion(wolf, satisfied, eat_grandmother).
Hmmm... that is pretty good. The last thing we need is a bit more temporal and spatial details. Which ChatGPT produces as:
% Temporal dependencies
before(start_journey, go_through).
before(go_through, arrive_at).

% Spatial dependencies
adjacent(forest, path).
adjacent(path, grandmother's_house).
Finally, we can ask for a few query examples, which ChatGPT produces as:
Who is Little Red Riding Hood's grandmother?
?- relationship(little_red_riding_hood, Grandmother, granddaughter).

What is in Little Red Riding Hood's basket?
?- has(little_red_riding_hood, Basket), contains(Basket, Item).

What is the emotional state of Little Red Riding Hood when she arrives at the Grandmother's house?
?- emotion(little_red_riding_hood, Emotion, arrive_at_grandmother's_house).

What actions must Little Red Riding Hood take before arriving at the Grandmother's house?
?- before(Action, arrive_at).

What locations are adjacent to the forest?
?- adjacent(forest, Location).
PS: Prolog because it is compact and easy to express in production with a monadic FP style.
PS: In the first version of this post, ChatGPT produced incompatible snippets, but as I tried to clean up the post's style, the new snippets all fit together, and the post was updated.

James Litsios, 2022.

Tuesday, September 06, 2022

Learning as a personal experience: James Taylor vs George Polya

How best to learn? How best to build deep personal growth? 

I noted this 1995 advice from James Taylor (in this YouTube), on how to become a 'musician like him':

Be as self-contained as possible, to keep the overheads to a minimum... spend as much time free and lonely as you can. ... I think lonely and free go together... somehow. And then you can’t help but evolve, if you keep your mind open, and you are not denying your experience, not shutting yourself down, not sort of clamping yourself down, or letting other wastes of time come in and claim all of your time. If you keep yourself open and free, then things will happen to you, and you will be educated by them and you will evolve, you will grow.

Is this good advice? Does deep personal growth only happen alone?

To contrast this with George Polya who states in 1966:

Teaching is giving opportunities to students to discover things by themselves.

We might rephrase this as:

To learn, students must be given the opportunity to discover things by themselves.

So in fact Polya is also saying that learning happens by actions of the students, not anyone else.

There are a few things to mention here:

  1. We may learn by discovery, we may learn by imitation. Both James Taylor and George Polya are referring to learning by discovery. Learning by imitation, by definition, cannot be done alone.
  2. Polya is not excluding that students 'discover together'. What is excluded is learning where each student does not personally experience the discovery from 'not learned' to 'learned'.
  3. For Polya, the teacher is responsible that each student experiences their learning.
  4. For James Taylor, the student is responsible to 'shut-away' others to experience alone their learning.
  5. Polya is referring to learning math, James Taylor to learning to be a singer song writer.
  6. Learning math can be organized with others, learning the humanity and introspection that goes into song writing is much about "maintaining one's aloneness", which some might call narcissism, remoteness, egoism, detachment, a religious experience, or even being a hermit.
Both advices are similar: learning is best experienced personally, and sometimes experiences learned alone change what is learned. And one cannot help to note that James Taylor naturally expresses the individual nature of learning in an asocial 'push others away' manner, while George Polya stays in a social and organized setting of teachers and students.

All original content copyright James Litsios, 2022.

Saturday, May 14, 2016

Learning to fall

A style of youtube skateboard videos, is to show someone attempting a trick, to fail over and over, often with repeated falling to the ground, until finally succeeding, and with that success come the end of the video. What a casual observer may not know, is that pavement hurts. And yet, here are these guys (really, mostly guys), that seem to be happy to torture themselves, over and over.
 A few years ago, one of my favorite expressions was “no pain, no gain”.  I would work around the clock, I would “take the crap”, and I would optimistically suffer.

I still do that! But I do not say “no pain, no gain” anymore. Instead I have come to understand that certain forms of learning are mostly about managing failures while pursuing those potential gains. In some sense, learning is like a game of poker: you need to pay to stay in the game, and that hurts, yet you expect to make that back when you win. And so it is with certain areas of learning, like when learning skateboard tricks on hard pavement, or like when working hard over many years to learn a new area.

There is an interesting aspect to this story: you can shield yourself from much sensation of pain by becoming “one” with your learning goals. Personal experience is much shaped by how we interpret our senses. And a key learning in life is that we can endure hardships and “move mountains” but we must be sufficiently fanatical enough in our approach that we do truly change our sense of perception. The good thing is that this makes life more interesting, as we focus our mind into new areas, the bad thing is that if you are not careful, that “change of sense of perception” can alienate you, or cause harm to others