Digitala Vetenskapliga Arkivet

Change search
CiteExportLink to record
Permanent link

Direct link
Cite
Citation style
  • apa
  • ieee
  • modern-language-association-8th-edition
  • vancouver
  • Other style
More styles
Language
  • de-DE
  • en-GB
  • en-US
  • fi-FI
  • nn-NO
  • nn-NB
  • sv-SE
  • Other locale
More languages
Output format
  • html
  • text
  • asciidoc
  • rtf
Prompt Engineering Using Grammar for Predicting Domain-Specific Code from Natural Language: Comparing in-context learning and fine-tuning with grammar-prompting
KTH, School of Electrical Engineering and Computer Science (EECS).
2024 (English)Independent thesis Advanced level (degree of Master (Two Years)), 20 credits / 30 HE creditsStudent thesisAlternative title
Använding av grammatik för skriva domän specifik kod från naturligt språk : En jämförelse mellan in-context-lärande och finjustering med grammatikpromptning (Swedish)
Abstract [en]

Domain-specific languages (DSLs) offer a high level of abstraction, enabling engagement with underlying technology focusing on domain-relevant con- cepts rather than implementation details. However, the specificity of DSLs presents a challenge due to their unique syntax and semantics, which can create a steep learning curve for users unfamiliar with the domain or lacking technical proficiency. This thesis explores the ability of large language models (LLMs) to generate DSL code from natural-language prompts by augmenting the prompt with the grammar of the language in the form of Extended Backus- Naur Form (EBNF). The model is then asked to predict the code alongside the minimum set of the grammar rules needed for parsing the code in a chain- of-thought manner. We compare three learning configurations: in-context learning with 16 and 32 examples, and fine-tuning. The study uses two distinct DSLs, Geoquery and Overnight blocks, and a mix of the languages to evaluate the models performance across grammatical domains. The results show that fine-tuning greatly improves program accuracy, with grammar-prompting enhancing consistency and performance, especially in multi-language settings. Fine-tuned models also generate valid grammars that align with the predicted programs. Due to the small dataset used for the thesis, the definite effect of grammar-prompting on program accuracy remains inconclusive, requiring further investigation.

Abstract [sv]

Domänspecifika språk (DSLs) möjliggör interaktion med underliggande teknik med fokus på domänspecifika koncept snarare än implementations- detaljer. DSLs kräver dock att användaren är bekant med dess unika syntax och semantik vilket kan innebära svårigheter för användare utan domänkunskap eller teknisk kompetens. Denna avhandling undersöker därmed hur stora språkmodeller (LLMs) kan användas för att generera DSL- kod från naturligt språk genom att lägga till en beskrivning av språket i input-prompten i form av dess gramatik i Extended Backus-Naur format (EBNF). Modellen ombeds därefter att generera koden tillsammans med den minsta uppsättningen grammatikregler som behövs för att tolka koden. Vi jämför tre inlärningskonfigurationer: in-context-lärande med 16 respektive 32 exempel, och finjustering. Studien undersöker två olika DSL:er, Geoquery och Overnight blocks, samt en blandning av språken för att utvärdera samma models kapacitet att resonera över olika språkliga domäner. Resultaten visar att finjustering avsevärt förbättrar programnoggrannheten, där grammatik- promptning ytterliggare förbättra modellens stabilitet och prestanda, särskilt i flerspråkiga sammanhang. Finjusterade modeller genererar även giltig grammatik som överensstämmer med de genererade programmen. På grund av de små datamängderna som använts för avhandlingen krävs dock vidare undersökning för att avgöra den definitiva effekten av grammatik-promptning.

Place, publisher, year, edition, pages
2024. , p. 92
Series
TRITA-EECS-EX ; 2024:916
Keywords [en]
Large Language Models, Fine-tuning, natural-language Processing, Semantic Parsing, Domain-specific Languages
Keywords [sv]
Stora språkmodeller, Finjustering, Semantisk tolkning, Datorlingvistik, Domänspecifika språk
National Category
Computer and Information Sciences
Identifiers
URN: urn:nbn:se:kth:diva-361029OAI: oai:DiVA.org:kth-361029DiVA, id: diva2:1943520
External cooperation
Bontouch AB
Supervisors
Examiners
Available from: 2025-03-13 Created: 2025-03-11 Last updated: 2025-03-13Bibliographically approved

Open Access in DiVA

fulltext(4264 kB)69 downloads
File information
File name FULLTEXT02.pdfFile size 4264 kBChecksum SHA-512
c1581046a833e07cdba4ce618cabc95f8295c9dea0ca14d185071908d6ed3ed04ae77d32524750d9968f8e5493f9b3bbb85c53ae8c86510a6aebfad1ee8fa37d
Type fulltextMimetype application/pdf

By organisation
School of Electrical Engineering and Computer Science (EECS)
Computer and Information Sciences

Search outside of DiVA

GoogleGoogle Scholar
Total: 69 downloads
The number of downloads is the sum of all downloads of full texts. It may include eg previous versions that are now no longer available

urn-nbn

Altmetric score

urn-nbn
Total: 446 hits
CiteExportLink to record
Permanent link

Direct link
Cite
Citation style
  • apa
  • ieee
  • modern-language-association-8th-edition
  • vancouver
  • Other style
More styles
Language
  • de-DE
  • en-GB
  • en-US
  • fi-FI
  • nn-NO
  • nn-NB
  • sv-SE
  • Other locale
More languages
Output format
  • html
  • text
  • asciidoc
  • rtf