Table of Contents
Fetching ...

LLM4SFC: Sequential Function Chart Generation via Large Language Models

Ofek Glick, Vladimir Tchuiev, Marah Ghoummaid, Michal Moshkovitz, Dotan Di-Castro

TL;DR

LLM4SFC addresses the challenging task of generating executable Sequential Function Charts from natural language by introducing a reduced SFC representation, structured generation, and retrieval-augmented fine-tuning. The framework integrates bidirectional PLCopen/reduced representation parsing, targeted fine-tuning (including subgraph masking), and few-shot prompting, producing syntactically valid and safe SFCs that can be exported to PLC IDEs. Empirical results show strong performance for proprietary LLMs and meaningful gains for open-source models with structured decoding and few-shot context, along with high semantic alignment as measured by MATCH. The work highlights data scarcity and visual-semantic aspects as key limitations, suggesting future multi-modal setups and broader data collection to broaden applicability beyond manufacturing SFCs.

Abstract

While Large Language Models (LLMs) are increasingly used for synthesizing textual PLC programming languages like Structured Text (ST) code, other IEC 61131-3 standard graphical languages like Sequential Function Charts (SFCs) remain underexplored. Generating SFCs is challenging due to graphical nature and ST actions embedded within, which are not directly compatible with standard generation techniques, often leading to non-executable code that is incompatible with industrial tool-chains In this work, we introduce LLM4SFC, the first framework to receive natural-language descriptions of industrial workflows and provide executable SFCs. LLM4SFC is based on three components: (i) A reduced structured representation that captures essential topology and in-line ST and reduced textual verbosity; (ii) Fine-tuning and few-shot retrieval-augmented generation (RAG) for alignment with SFC programming conventions; and (iii) A structured generation approach that prunes illegal tokens in real-time to ensure compliance with the textual format of SFCs. We evaluate LLM4SFC on a dataset of real-world SFCs from automated manufacturing projects, using both open-source and proprietary LLMs. The results show that LLM4SFC reliably generates syntactically valid SFC programs effectively bridging graphical and textual PLC languages, achieving a generation generation success of 75% - 94%, paving the way for automated industrial programming.

LLM4SFC: Sequential Function Chart Generation via Large Language Models

TL;DR

LLM4SFC addresses the challenging task of generating executable Sequential Function Charts from natural language by introducing a reduced SFC representation, structured generation, and retrieval-augmented fine-tuning. The framework integrates bidirectional PLCopen/reduced representation parsing, targeted fine-tuning (including subgraph masking), and few-shot prompting, producing syntactically valid and safe SFCs that can be exported to PLC IDEs. Empirical results show strong performance for proprietary LLMs and meaningful gains for open-source models with structured decoding and few-shot context, along with high semantic alignment as measured by MATCH. The work highlights data scarcity and visual-semantic aspects as key limitations, suggesting future multi-modal setups and broader data collection to broaden applicability beyond manufacturing SFCs.

Abstract

While Large Language Models (LLMs) are increasingly used for synthesizing textual PLC programming languages like Structured Text (ST) code, other IEC 61131-3 standard graphical languages like Sequential Function Charts (SFCs) remain underexplored. Generating SFCs is challenging due to graphical nature and ST actions embedded within, which are not directly compatible with standard generation techniques, often leading to non-executable code that is incompatible with industrial tool-chains In this work, we introduce LLM4SFC, the first framework to receive natural-language descriptions of industrial workflows and provide executable SFCs. LLM4SFC is based on three components: (i) A reduced structured representation that captures essential topology and in-line ST and reduced textual verbosity; (ii) Fine-tuning and few-shot retrieval-augmented generation (RAG) for alignment with SFC programming conventions; and (iii) A structured generation approach that prunes illegal tokens in real-time to ensure compliance with the textual format of SFCs. We evaluate LLM4SFC on a dataset of real-world SFCs from automated manufacturing projects, using both open-source and proprietary LLMs. The results show that LLM4SFC reliably generates syntactically valid SFC programs effectively bridging graphical and textual PLC languages, achieving a generation generation success of 75% - 94%, paving the way for automated industrial programming.

Paper Structure

This paper contains 38 sections, 4 equations, 5 figures, 4 tables.

Figures (5)

  • Figure 1: Overview of the LLM4SFC generation pipeline. The user provides a natural language prompt describing the desired scenario. Semantically similar SFCs are embedded into the model's context as few-shot demonstrations. The LLM then generates a reduced representation of the SFC. This reduced representation encodes the structural topology of the control logic while abstracting away redundant metadata. The reduced SFC is parsed into the PLCopen XML format. The final output is a vendor compatible SFC diagram that can be viewed or edited in standard IDEs such as TwinCAT.
  • Figure 2: Conversion between PLCopen XML representations and our reduced internal graph structure. (a) An example SFC as encoded in PLCopen XML, including convergence and divergence nodes and vendor-specific metadata. (b) The reduced representation omits redundant metadata and infers structural roles (e.g., branching) from transition semantics.
  • Figure 3: Illustration of our proposed Subgraph Masking fine-tuning strategy. (a) The original reduced SFC graph. (b) A subgraph consisting of structurally related steps and transitions is randomly masked during training. (c) The model is trained to reconstruct the missing subgraph components, promoting a deeper structural understanding of SFC topology. This technique combines graph-masked language modeling and FIM objectives to enhance the model's ability to generate coherent and complete control logic segments.
  • Figure 4: Performance comparison of various models on Pass@k and Safety@k metrics. For each model, we show the results from its best-performing configuration based on the Pass@k (Generation) score. Proprietary models (solid bars) use $k=10$, while open-source models (hatched bars) use $k=5$. The plot highlights a general trend of proprietary models outperforming open-source models across these metrics. Further error analysis of these performance differences is discussed in the section \ref{['subsec:error-analysis']}.
  • Figure 5: Comparison of generation success rates across different experimental setups. (a) Proprietary models outperform open-source models in both zero-shot and few-shot scenarios. (b) Structured generation improve generation success for both proprietary and open-source models compared to unstructured prompts. (c) Among decoding strategies tested for open-source models, NTP offers only an edge over the masking and combined approaches.