I've tried ChatGPT to generate GF code...

29 views
Skip to first unread message

Roman Suzi

unread,
Jan 7, 2023, 6:09:43 AM1/7/23
to Grammatical Framework
Hi!
Just though it would be fun to share with you:
----------------------
Q: How to express the following sentence in grammaticalframework language: "John , the first car to which I have given oil"

A: You can express the sentence "John, the first car to which I have given oil" in Grammatical Framework (GF) as follows:

NP = (Det) * (N) * (PP)
Det = "John" | "the"
N = "first car"
PP = "to which" * "I" * "have given" * "oil"

Here, NP stands for a noun phrase, Det for a determiner, N for a noun, and PP for a prepositional phrase. The * symbol indicates that the preceding element can be repeated zero or more times.

To generate the sentence in English, you can use the following GF command:

print (NP Det N PP)

This should produce the output John the first car to which I have given oil.

---------------------

Honestly, I expected a bit better reply. For example, some simple requests produced working Python or Haskell code:

-------------------------------

Q: Can you write a program in Haskell to sum every second element of a list?

...

Q2: Can you add main function as well to output the result?

A2:

sumSecondElements :: Num a => [a] -> a
sumSecondElements xs = sum [x | (x,i) <- zip xs [1..], i `mod` 2 == 0]

main :: IO ()
main = do
    let result = sumSecondElements [1, 2, 3, 4, 5]
    putStrLn $ "The sum of every second element is: " ++ show result

-----------------------

It even gives an example how to run it:

-----------------------

$ ghc sum_second_elements.hs

$ ./sum_second_elements The sum of every second element is: 9

-----------------------

(of course, the result is not 9, it should be 6)

Probably, there is just not enough GF code to teach LLM?

I've also done some other experiments, like asking to write a program with a catch, GPT never understood the catch, even though I provided two hints: it just mindlessly added something to the problem, but the end result was the same. All that is still impressive, no doubt, but it also means LLM can't really deal with quite simple logic on it's own.

As a bonus, I've asked for POS analysis, which caused some kind of error in the system, but here is at least something:

-----------------

Q: What are parts of speech of the sentence "John , the first car to which I have given oil"?

A: Error in body stream

Have given" is a verb phrase that consists of the auxiliary verb "have" and the main verb "given". "Oil" is a noun that functions as the object of the verb "have given".

So in this sentence, the parts of speech are:

  • Proper noun (subject): John
  • Determiner: the
  • Noun (direct object): first car
  • Preposition: to
  • Pronoun (subject): I
  • Auxiliary verb: have
  • Main verb: given
  • Noun (object): oil

-----------------------

I am not quite sure why "first car" is a noun... but other than that looks okeish.

With best regards,

Roman

Inari

unread,
Jan 16, 2023, 10:53:38 PM1/16/23
to Grammatical Framework
Thanks for sharing! (And great example sentence :-D)

ChatGPT is indeed pretty bad at generating GF code. It has also gotten the history of GF a bit backwards... https://cdn.discordapp.com/attachments/865094039422500864/1051153839975321650/Screenshot_2022-12-10_at_16.08.23.png 

Inari
Reply all
Reply to author
Forward
0 new messages