MODELO LÓGICO PARA AJUSTE FINO DE MODELOS DE LINGUAGEM BASEADO EM RECUPERAÇÃO AUMENTADA

BR102025001971A2Pending Publication Date: 2026-08-04FUNDACAO UNIV DE BRASILIA FUB
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
BR · BR
Patent Type
Applications
Current Assignee / Owner
FUNDACAO UNIV DE BRASILIA FUB
Filing Date
2025-01-31
Publication Date
2026-08-04

Smart Images

  • Figure 00000018_0000
    Figure 00000018_0000
  • Figure 00000018_0001
    Figure 00000018_0001
  • Figure 00000019_0000
    Figure 00000019_0000
Patent Text Reader
Need to check novelty before this filing date? Find Prior Art

Description

LOGICAL MODEL FOR FINE-TUNING OF LANGUAGE MODELS BASED ENHANCED RECOVERY FIELD OF THE INVENTION

[001] The technical field referred to in this invention is that of natural language processing (NLP) with specific applications in trade and customs operations, with a special focus on the codes of the Mercosur Common Nomenclature (NCM) and the Harmonized System (HS). The invention involves the use of large language models (LLM) for the processing and classification of commercial goods based on standardized nomenclatures. STATE OF THE ART

[002] LLMs are machine learning models for understanding and generating natural language, being trained with large volumes of text to understand, generate, and manipulate this type of language. LLMs have been widely applied to NLP, content generation, and education (KADDOUR, Jean et al. Challenges and applications of large language models. arXiv preprint arXiv:2307.10169, 2023).

[003] The use of these LLMs has advantages such as their versatility, possibility of automation and scalability. On the other hand, factors such as their high computational cost, risks of biases and the impossibility of interpreting how their decisions were made, are points that challenge their widespread implementation (ZHAO, Wayne Xin et al. A survey of large language models. arXiv preprint arXiv:2303.18223, 2023). Petition 870250066455, dated 07 / 31 / 2025, page 5 / 19 / 15

[004] Taking it a step further, LLMs can have their potential expanded through the application of the technique known as "fine-tuning". This is the name given to the process of adjusting an LLM using a specific dataset to improve its performance on a particular task, thus allowing for improved accuracy and relevance of its responses. This adjustment involves additionally training the LLM with labeled data related to the desired application, allowing generalist LLMs to be adapted for specialized applications, significantly improving their usefulness and performance in specific contexts (XU, Runxin et al. Raise a child in large language model: Towards effective and generalizable fine-tuning. arXiv preprint arXiv:2109.05687, 2021).

[005] By performing fine-tuning, it is possible to obtain a huge increase in training efficiency, since by using an already trained LLM, instead of training one from scratch, time and resources are saved. However, apart from the dependence on high-quality labeled data, performing this process also carries the risk of overfitting, where the model becomes too specific and loses generalization (DING, Ning et al. Parameter-efficient fine-tuning of large-scale pre-trained language models. Nature Machine Intelligence, v. 5, n. 3, p. 220-235, 2023).

[006] In parallel with fine-tuning, another approach capable of complementing the capabilities of LLMs is a technique known as Retrieval-Augmented Generation (RAG). This technique integrates language generation with information retrieval, allowing the model to access external data and provide more informed and contextualized answers. Thus, instead of relying solely on the knowledge contained in the LLM, RAG searches for relevant information in external documents during the generation process, which improves the accuracy and relevance of the generated answers (LEWIS, Patrick et al. Retrieval-augmented generation for knowledge). Petition 870250066455, dated 07 / 31 / 2025, page 6 / 19 / 15 intensive NLP tasks. Advances in Neural Information Processing Systems, v. 33, p. 9459-9474, 2020).

[007] Once you have access to up-to-date and specific information, the accuracy of the responses is increased when using RAG. In addition, your information is contextualized and can be verified during generation. On the other hand, in addition to the dependence on external quality data, integrating retrieval mechanisms can increase the complexity of the system (GAO, Yunfan et al. Retrieved augmented generation for large language models: A survey. arXiv preprint arXiv:2312.10997, 2023).

[008] Anantha and colleagues (2023) also explore methods to increase the effectiveness of RAG models by improving how contexts are selected and used during the retrieval process. Traditional models retrieve context based on static embeddings, which may not always align with the specific needs of the generation task, whereas if the context is dynamically adjusted, the model improves the relevance and coherence of the generated outputs, and the overall quality of generation in tasks such as tool retrieval and plan generation can be significantly improved (ANANTHA, Raviteja et al. Context tuning for retrieval augmented generation. arXiv preprint arXiv:2312.05708, 2023).

[009] Since both technologies, fine-tuning and RAG, already presented advantages separately, the combination of these techniques resulted in the technique known as Retrieval-Augmented Fine-Tuning (RAFT), which represented a significant advance in the adaptation of LLMs for specialized applications. RAFT involves incorporating information retrieved from an external database during the fine-tuning process, allowing the model not only to adjust its parameters based on the training data, but also to utilize relevant additional information. Petition 870250066455, dated 07 / 31 / 2025, p. 7 / 19 / 15, which allows for a higher level of precision and mitigation of biases in the generated responses. On the other hand, it inherits the difficulties of fine-tuning and RAG, so issues such as complexity, dependence on external data, and high computational cost still persist (ZHANG, Tianjun et al. Raft: Adapting language model to domain-specific rag. arXiv preprint arXiv:2403.10131, 2024).

[0010] Regarding the process used by RAFT, patent document CN117035064 refers to a method for retrieving an enhanced LLM, where the aim is to construct a search expression and insert it into a retrieval model to be used as input for the LLM. Furthermore, it provides for training where the document retrieved by the retrieval model is used to fine-tune the LLM after generating knowledge, with the feedback model being used for its training, so that both are mutually optimized. The document, despite being published before the term RAFT was coined, describes a system that utilizes both of its principles: retrieval and fine-tuning.

[0011] Document CN118071543 describes an evaluation method comprising the steps of building a large-scale corpus, pre-training an LLM based on this corpus, fine-tuning, building a retrieval enhancement module, and building a question-and-answer module with report generation based on the data acquired by the system. Document US11003865 describes a method for pre-training and fine-tuning an LLM, whereby its knowledge retriever can obtain documents from an unlabeled pre-training corpus, generate its own training tasks, and learn to retrieve documents relevant to those tasks. This retriever can also be fine-tuned through supervised questions. Thus, the invention provides models that can intelligently retrieve useful information from a large corpus. Petition 870250066455, dated 07 / 31 / 2025, page 8 / 19 / 15 unlabeled corpus, allowing for reduced storage space and complexity.

[0012] Regarding the use of NCM and HS codes, patent document KR101947669 refers to a method, which uses machine learning, to automatically process items with HS classification, aiming to enable both specialists and non-specialists to work with the classification of these items. Furthermore, document CN116012101 proposes a method to automatically identify customs codes using Big Data. This method combines the name of the merchandise and attribute keywords entered by a user to obtain customs codes by matching the two models.

[0013] In a non-patent context, Amel et al. (2024) propose a multimodal HS code prediction approach using deep learning models and image and text assets obtained through customs declarations combined with information from the e-commerce platform (AMEL, Otmane et al. Multimodal Approach for Harmonized System Code Prediction. arXiv preprint arXiv:2406.04349, 2024).

[0014] Although the three examples above do not directly deal with products involving the NCM code, they all present products that involve the use of HS codes, a coding system from which the NCM coding system was derived.

[0015] Regarding the use of smaller LLMs, Corrêa and colleagues (2024) focus on the development of compact and efficient language models trained specifically for the Brazilian Portuguese language and are part of an open-source initiative that aims to create small, accessible, and usable language models in resource-limited environments. These models are designed to provide similar benefits. Petition 870250066455, dated 07 / 31 / 2025, page 9 / 19 / 15 to larger language models, while maintaining a reduced size and computational demand (CORRÊA, Nicholas Kluge et al. TeenyTinyLlama: open-source tiny language models trained in Brazilian Portuguese. arXiv preprint arXiv:2401.16640, 2024).

[0016] In the process of building the RAFT database, the chain-of-thought (CoT) structure is used for fine-tuning applied to LLM in conjunction with RAG, the process of which can be seen in Figure 1. The RAG method can be explained in five main steps, where (1) the question / answer is passed to a model, which transforms it into a vector representation where this vector captures the semantic characteristics of the question / answer; (2) the question / answer vector is then used to search for information in the vector database that contains pre-calculated vector representations of various documents, allowing an efficient and fast search for relevant documents; (3) the vector database returns a set of documents that are most similar to the question / answer vector, classified and filtered, resulting in a top-k set of relevant documents that will form the retrieved context;(4) the retrieved documents are then combined and provided as additional context for the LLM, where the context helps the model to better understand the question / answer by providing additional information that may not be present in the original input; (5) finally, the LLM uses the original question / answer and the retrieved context to generate an answer. The model integrates the context information with its pre-trained knowledge to provide a relevant and informative answer.

[0017] This task depends on the use of a powerful LLM, as it creates a series of arguments that are relevant and irrelevant to the model's response. This is because its use presupposes that the model must learn to distinguish between which arguments the response will be based on. Petition 870250066455, dated 07 / 31 / 2025, page 10 / 19 / 15

[0018] CoT is the reasoning chain, created based on a dataset of long texts, where an LLM will read and interpret the semantics of the text to build the training base: Question, CoT, Reasoning, Answer. This process is detailed in Figure 2, where the figure in the upper left corner illustrates this approach of adapting LLMs to read solutions from a set of positive and negative documents, in contrast to the standard RAG configuration, where models are trained based on the outputs of the retriever, which is a mixture of memorization and reading. At the time of testing, all methods follow the standard RAG configuration, being provided with the top-k retrieved documents in context.

[0019] The following details how the RAFT databases and the present technology are constructed, highlighting their differences and the improvements of this innovation. Regarding the composition of the dataset, in RAFT, each data point in the dataset consists of a question + a set of documents + a CoT-style response generated from one of the documents. In the present technology, each data point in the dataset consists of a question + context (CoT) and a CoT-style response generated from the context.

[0020] Regarding document types, in RAFT, we have oracle documents, which are documents that contain the correct answer to the question, and distractor documents, which are documents that do not contain information relevant to the answer. In the present technology, we have the “Query + Context” set, which are records that contain the correct answer to the question as well as the correct context.

[0021] Regarding the training process, in RAFT, the model is adjusted using supervised training techniques, where it learns to generate answers from the documents and questions provided, and is trained to recognize and use Petition 870250066455, dated 07 / 31 / 2025, page 11 / 19 / 15 relevant documents or oracle while ignoring irrelevant or distracting ones. In the current technology, the model is adjusted using supervised training techniques, where it learns to generate answers from the contexts and questions provided.

[0022] Regarding reasoning in CoT, in RAFT, responses include a chain of reasoning that explains the steps taken to reach the conclusion; the chain of reasoning helps guide the model to the answer and enrich its understanding; and finally, example responses include quotes from the relevant context, enclosed within special markers (e.g., ##begin_quote## and ##end_quote##). In the current technology, this process is simplified by simply delimiting the two fields [Question + context (CoT)], [context (CoT) + Response].

[0023] Regarding implementation details, in RAFT, during the training phase, the dataset is prepared by maintaining oracle documents in some cases and only distractor documents in others. Then, at the time of testing, the model is provided with the question and the top-k documents retrieved by the RAG pipeline, regardless of the retrieval method used during training. In the present technology, the difference occurs during the training phase, where the dataset is provided by the pairs Query + Context” = {[Question + context (CoT)], [context (CoT) + Response]}.

[0024] Given the above, it is clear that there are still some obstacles to overcome in the use of RAFT, especially the complexity of the training process and the dependence on external data for recovery in the RAG as well as for fine-tuning. While building the database for RAFT is so complex that the use of another powerful LLM is indispensable, this APPLICATION presents a solution, called SLIM-RAFT (Simplified Logical Intelligent Model for RAFT), where this situation is optional. Therefore Petition 870250066455, dated 07 / 31 / 2025, page 12 / 19 / 15 In this way, the present REQUEST innovates by simplifying the training process and facilitating the creation of the database for fine-tuning and for the data recovery process. BRIEF DESCRIPTION OF THE FIGURES

[0025] The figures listed below are intended to enhance understanding of the present technology.

[0026] Figure 1 — Overview of the RAC method.

[0027] Figure 2 - Overview of the RAFT method.

[0028] Figure 3 - Overview of the SLIM-RAFT method. DETAILED DESCRIPTION OF THE INVENTION

[0029] The SLIM-RAFT proposal is to build a training dataset using a simplified CoT structure for fine-tuning applied to a small LLM to be used with RAG. The existing model called RAFT (Retrieval Augmented Fine-Tuning) proposes a training dataset for fine-tuning in a complex CoT (Chain-of-Thought) structure, formed by long texts, some documents being relevant to the response and others irrelevant. This fine-tuning would be applied to a large LLM model, where it would be embedded in a Retrieval Augmented Generation (RAG) structure.

[0030] The innovation of the SLIM-RAFT method is presented in two elements: the use of a smaller, pre-trained LLM in Portuguese and the optimized simplification of prompt engineering. Petition 870250066455, dated 07 / 31 / 2025, page 13 / 19 / 15 (CoT) used for building the fine-tuning training database. These two points are detailed below.

[0031] The first point of innovation involves the use of a smaller LLM pre-trained in Portuguese. The LLMs widely used in the market were created by large technology companies at a very high cost. As such, pre-training LLMs by small and medium-sized institutions is unfeasible. Furthermore, these models are pre-trained with gigantic text corpora, with their composition being approximately 90% in English and 10% in other languages, which often limits the performance of LLMs in languages ​​other than English.

[0032] Because of this, “TeenyTinyLLaMa 160m” was chosen, a pre-trained LLM in Portuguese, which, in addition to the advantage of the language, has a significantly smaller size than other LLMs. This LLM has 160 million parameters, in contrast, for example, to LLaMA 3, the most widely used open-source LLM, with 8 billion parameters. This number is even further from ChatGPT 4, which has approximately 1 trillion parameters. Due to its size, the performance of TeenyTinyLLaMa 160m is clearly limited compared to LLaMA 3, especially regarding generic text generation tasks. However, it performs specialized tasks with quality, such as those handled by the SLIM-RAFT model.

[0033] The second point involves simplified and optimized prompt engineering (CoT) for building the fine-tuning training database. The construction of the fine-tuning training database was done within the CoT technique, but in a simplified way, with logical and generic context rules. This simplification consists of creating simple, but logical questions, with generic rules that can be applied to the predominant knowledge domain in the database. Petition 870250066455, dated 07 / 31 / 2025, page 14 / 19 / 15

[0034] In the simplified CoT, the reasoning chain is created with few, generic, and simplified rules, in the following format: Question + context (CoT), context (CoT) + Answer. This process is detailed in Figure 3, where the figure demonstrates that the method is composed of two parts. On the left side of the figure is the common structure of RAG, the only difference being the connection with an adjusted LLM (with fine-tuning), which also happens in the RAFT method. In the case of SLIM-RAFT, the use of a smaller, pre-trained LLM in Portuguese is proposed. On the right side of the figure is shown the structure of the fine-tuning proposed in the SLIM-RAFT method, where the training set is composed of several question-answer pairs plus the context (Query + Context). In this case, the context is a sequence of reasoning about the characteristics of the elements.The contexts of these pairs are constructed following the prompt engineering technique called CoT (from the English "Chain-of-Thought"), according to a determined sequence of logical and simple statements that make up the context of the question-answer pair.

[0035] The chain reasoning model created for SLIM-RAFT was named “Sequence-of-Sets - SoS”. It is a model based on the property of transitivity between sets, which is a property that is established when an element is related to a second element, and this is related to a third, then the first element is related to the third. For example: “a GA ^ 'a' belongs to 'A' (1)”, “A ^ B ^ 'A' is contained in 'B' (2)” and “λ a GB ^ therefore, 'a' belongs to 'B' (3)”. The objective of this technique is to reinforce the classification of the elements processed in the model.

[0036] Thus, to build the training data base in SLIM-RAFT mode, there are three steps. The first (1) is where a domain expert creates a small set of questions and answers, for example, “What is the product category 'product'?”; Petition 870250066455, dated 07 / 31 / 2025, page 15 / 19 / 15 after, (2) variations of the question and answer set (an LLM can be used) are constructed, for example, “Could you specify the category to which the product 'product' belongs?”; and finally, (3) the mask of the question and answer set is filled in. for example, “What is the category of the product 'fresh apple package'?”, “Could you specify the category to which the product 'fresh apple package' belongs?”. The total number of records in the training data set will be: N = q χ v χ n. Where “q” is the number of questions and answers created by the domain expert, “v” is the number of variations of each question and answer unit and “n” is the total number of samples from the NCM database. EXAMPLES OF CONCRETIZATIONS OF THE INVENTION

[0037] As seen in the detailed description of each activity, the SLIM-RAFT method provides a simpler and cheaper process for building the fine-tuning database for the LLM. In tests performed on simpler tasks, mainly with shorter texts, there was no loss of efficiency in the model or accuracy of the responses. Tasks with long texts or extensive documents were not tested, as this is not the intended use of SLIM-RAFT, which primarily works with smaller LLM models.

[0038] The results of SLIM-RAFT were evaluated through a comparative analysis of responses delivered by it and three other tested models, which were tested and evaluated by ChatGPT 4. The first model was TeenyTinyLlama with tiny460M without fine-tuning on the dataset, named TTL; the second model was ChatGPT 4, named GPT; the third model was TeenyTinyLlama with fine-tuning on the NCM dataset, named NCM-TTL; and finally, the fourth model was TeenyTinyLlama with Petition 870250066455, dated 07 / 31 / 2025, page 16 / 19 / 15 fine-tuning of the NCM dataset using SLIM RAFT, named SLIM-RAFT.

[0039] The evaluation used 100 questions and answers not included in the fine-tuning training set. These 100 questions were presented to the models, and their answers were recorded and compared. The models' answers were sent to ChatGPT 4, which compared the outputs produced with the desired outputs. To ensure impartiality in the evaluation, it is important to note that ChatGPT 4 was not informed which model each answer referred to.

[0040] ChatGPT 4 assessed the quality of each response, scoring it on a scale of 0 to 10. The final score for each model represents the average of the scores assigned to each response. Table 1 presents the results of this assessment, where it can be seen that the SLIM-RAFT model obtained the best score of 8.63 with a standard deviation of 2.30 in the 100 question-answer pairs. Table 1: Score resulting from the four models. Model Average Standard Deviation Min. Max. TTL 0.2 0.98 0.5 NCM-TTL 4.71 3.53 0.10 GPT 4.5 1.39 0.5 SLIM-RAFT 8.63 2.30 0.10

[0041] Table 2 provides a clear comparison of the responses generated by all models, with the desired response serving as a reference for evaluation. This reference response defines a standard against which the performance of the models can be measured. Petition 870250066455, dated 07 / 31 / 2025, page 17 / 19 / 15 Table 2: Comparison of results from the four models Questions / Answers and Sample Answers Question What is the correct NCM category for the product: VEJA PERF.NAT PERF.SUAVE 1LT CLEANER? Answer only the category description. If you don't know, answer with the closest category. Do not add any other comments to your answer. Expected answer Other organic surface-active agents (except soaps); surface-active preparations, washing preparations (including auxiliary washing preparations) and cleaning preparations (including multi-purpose and cleaners), even containing soap, except for the products described in CEST 11.001.00, 11.004.00, 11.005.00 and 11.006.00; in packaging with a content of less than or equal to 50 liters or 50 kg. TeenyTinyLLaMA I cannot answer based on the information provided. However, I can provide a general explanation of how to categorize NCM products, including specific categories and their respective subcategories.ChatGPT 4 Preparations for cleaning TeenyTinyLLaMA FT PT NCM The correct NCM category is: Organic surface-active agents (excluding soaps); surface-active preparations, washing preparations (including auxiliary washing preparations) and cleaning preparations, even if containing soap, except those of heading 34.01. - Preparations packaged for retail sale SLIM-RAFT the product VEJA PERF.NAT PERF. SUAVE 1LT CLEANER has the category: Soaps, organic surface-active agents, washing preparations, lubricating preparations, artificial waxes, prepared waxes, polishing and cleaning products, candles and similar articles, modeling pastes, waxes for. Petition 870250066455, dated 07 / 31 / 2025, pages 18 / 19 / 15 Dentistry and dental compositions based on gypsum. - Organic surface-active agents (except soaps); Surface-active preparations, washing preparations (including auxiliary washing preparations) and cleaning preparations, whether or not containing soap, other than those of heading 34.01. - - Preparations put up for retail sale

[0042] As the examples show, the SLIM-RAFT model demonstrated significantly superior performance to ChatGPT 4 in interpreting and classifying product descriptions according to the NCM code, which indicates that even being a smaller-scale LLM, with the addition of specific domain knowledge it was able to outperform a more powerful LLM in specialized tasks while maintaining low execution costs.

[0043] The technique for simplifying the construction of the chain of thought (CoT) called Sequence-of-Sets - SoS as proposed in the APPLICATION, not only reduced costs, but also proves to be replicable in other domains, i.e., specialized LLMs with high precision.

Claims

[001] SIMPLIFIED INTELLIGENT LOGIC MODEL FOR FINE-TUNING BASED ON ENHANCED RECOVERY, characterized by a simplified training base for fine-tuning applied to a small LLM, to be used in conjunction with the RAG. [002] SIMPLIFIED INTELLIGENT LOGIC MODEL FOR FINE-TUNING BASED ON ENHANCED RECOVERY, according to claim 1, characterized by a training base constructed using the simplified Chain-of-Thought structure, composed of (1) question (question + context) and (2) context (context + response).[003] SIMPLIFIED INTELLIGENT LOGIC MODEL FOR FINE-TUNING BASED ON AUGMENTED RECALL, according to claims 1 and 2, characterized by containing the following steps in the construction of the training base: Step 1 - A domain expert creates a small set of questions and answers; Step 2 - Variations of the set of questions and answers are constructed; Step 3 - The mask of the set of questions and answers is populated. [004] SIMPLIFIED INTELLIGENT LOGIC MODEL FOR FINE-TUNING BASED ON AUGMENTED RECALL, according to claims 1, 2 and 3 characterized by its use in natural language processing and artificial intelligence for applications in commerce and Petition 870250008139, dated 01 / 31 / 2025, page 25 / 82. 2 / 2 Customs operations using codes from the Mercosur Common Nomenclature (NCM).