Statistical analysis-oriented cross-language code generation method and device, equipment and medium
Patent Information
- Application Number
- CN202610434321.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2026-04-03
- Publication Date
- 2026-10-09
- Estimated Expiration
- 2046-04-03
AI Technical Summary
[0005]本公开提供一种面向统计分析的跨语言代码生成方法及装置、设备及介质,至少在一定程度上克服相关技术中无法利用用户提供的自然语言,生成跨编程语言的统计分析执行代码的问题
[0017]本公开的实施例中提供的面向统计分析的跨语言代码生成方法及装置、设备及介质,在获取到样本数据集、初始统计需求信息和初始语义中枢模型后,将样本数据集和初始统计需求信息输入至初始语义中枢模型中,得到预设编程语言对应的多套初始统计分析执行代码,分别运行各套代码得到对应的结果向量,根据各个结果向量进行一致性校验,并根据校验结果生成模型修补指令对初始语义中枢模型进行更新,得到目标语义中枢模型;获取统计需求信息,其中,所述统计需求信息包括:目标编程语言,所述目标编程语言为预设编程语言中的任意一种编程语言;将所述统计需求信息输入至目标语义中枢模型,输出所述目标编程语言对应的统计分析执行代码。本公开实施例能够得到可以跨语言输出统计分析执行代码的语义中枢模型,进而可以在统计分析过程中利用用户提供的自然语言提供多种编程语言并按需灵活生成可靠的统计分析执行代码。
Smart Images

Figure CN122346304B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of data processing technology, and in particular to a method, apparatus, device and medium for cross-language code generation for statistical analysis. Background Technology
[0002] As social science and applied statistics scenarios become increasingly complex, statistical researchers often use natural language to describe the analysis objectives and data characteristics, and hope to obtain semantically consistent and reproducible execution results across different statistical software.
[0003] In related technologies, statistical researchers typically rely on manually transcribing natural language into scripts specific to a particular ecosystem, or using tools to generate initial statistical analysis code. However, this method is often limited to a single programming language or a single software stack. That is, when migrating across ecosystems, some key statistical semantics may not be explicitly modeled and aligned, leading to systematic deviations in the implementation and results of the same analytical intent across different software, making it difficult to meet the requirements of reproducibility and comparability.
[0004] On the other hand, intermediate representations (IRs) used in related technologies for model exchange / deployment primarily serve the interoperability between model structure and basic computational operations. Therefore, the domain of such IR representations is usually insufficient to bear the precise definition and constraints of key statistical semantics in social science statistics, making it difficult to achieve bidirectional mapping between natural language, statistical semantics, and multiple software codes. Summary of the Invention
[0005] This disclosure provides a method, apparatus, device, and medium for generating cross-language code for statistical analysis, which at least to some extent overcomes the problem in related technologies that it is impossible to generate statistical analysis execution code across programming languages using user-provided natural language.
[0006] Other features and advantages of this disclosure will become apparent from the following detailed description, or may be learned in part from practice of this disclosure.
[0007] According to one aspect of this disclosure, a cross-language code generation method for statistical analysis is provided, comprising: acquiring a sample dataset, initial statistical requirement information, and an initial semantic central model; inputting the sample dataset and the initial statistical requirement information into the initial semantic central model to map multiple sets of initial statistical analysis execution codes corresponding to preset programming languages; running each set of initial statistical analysis execution codes to obtain result vectors corresponding to each set of initial statistical analysis execution codes; performing consistency checks on each result vector to obtain consistency check results; if the consistency check results are abnormal, generating a first model repair instruction to update the initial semantic central model to obtain a target semantic central model; acquiring statistical requirement information, wherein the statistical requirement information includes: a target programming language, the target programming language being any one of preset programming languages; inputting the statistical requirement information into the target semantic central model and outputting the statistical analysis execution code corresponding to the target programming language.
[0008] In some embodiments, the step of generating a first model repair instruction to update the initial semantic central model to obtain a target semantic central model includes: inputting the corresponding key semantic parameters from each result vector into the initial semantic central model, automatically generating a first model repair instruction, wherein the first model repair instruction is a model repair instruction obtained after performing difference attribution in a preset order; updating the initial semantic central model based on the first model repair instruction to obtain an updated semantic central model; mapping multiple sets of updated statistical analysis execution codes corresponding to a preset programming language according to the updated semantic central model; running each set of updated statistical analysis execution codes to obtain each updated result vector; performing consistency verification on each updated result vector until the consistency verification result is normal, thereby obtaining the target semantic central model.
[0009] In some embodiments, the method further includes: acquiring new statistical requirement information; parsing the new statistical requirement information to generate a second model repair instruction, wherein the second model repair instruction contains anchor information, the anchor information including variable anchors, step anchors, or model ID anchors; incrementally updating the corresponding positions of the anchor information in the target semantic central model based on the second model repair instruction; and mapping the updated fragment of the statistical analysis execution code of the corresponding target programming language according to the updated semantic central model.
[0010] In some embodiments, the method further includes: obtaining irreversible summary information generated during the semantic central model update process, and storing the irreversible summary information locally; wherein the irreversible summary information includes: data fingerprint, version information of the updated semantic central model, patch chain hash, result vector, tolerance parameter and difference attribution record, and the patch chain hash is a hash value generated based on the first model patch instruction and the second model patch instruction.
[0011] In some embodiments, the method further includes: generating back-translated explanatory text information and key diagnostic summaries based on the consistency verification result and the target semantic central model, wherein the back-translated explanatory text information is used to clarify the update process of the semantic central model; and establishing an association between the key diagnostic summaries and the corresponding back-translated explanatory text information.
[0012] In some embodiments, the second model repair instruction corresponds to at least one structured editing operation among insertion, deletion, and modification.
[0013] In some embodiments, the preset programming languages include: R, Python, SPSS, and Stata.
[0014] According to another aspect of this disclosure, a cross-language code generation device for statistical analysis is also provided, comprising: an initial information acquisition module for acquiring a sample dataset, initial statistical requirement information, and an initial semantic central model; an initial execution code generation module for inputting the sample dataset and the initial statistical requirement information into the initial semantic central model, mapping to obtain multiple sets of initial statistical analysis execution codes corresponding to a preset programming language; a result vector calculation module for running each set of initial statistical analysis execution codes respectively, obtaining result vectors corresponding to each set of initial statistical analysis execution codes; a consistency verification module for performing consistency verification on each result vector, obtaining a consistency verification result; a semantic central model update module for generating a first model repair instruction to update the initial semantic central model if the consistency verification result is abnormal, obtaining a target semantic central model; a statistical requirement information acquisition module for acquiring statistical requirement information, wherein the statistical requirement information includes: a target programming language, which is any one of the preset programming languages; and a statistical analysis execution code generation module for inputting the statistical requirement information into the target semantic central model and outputting statistical analysis execution codes corresponding to the target programming language.
[0015] According to another aspect of this disclosure, an electronic device is also provided, comprising: a processor; and a memory for storing executable instructions of the processor; wherein the processor is configured to perform a cross-language code generation method for statistical analysis oriented by executing the executable instructions.
[0016] According to another aspect of this disclosure, a computer-readable storage medium is also provided, on which a computer program is stored, which, when executed by a processor, implements the cross-language code generation method for statistical analysis as described above.
[0017] The cross-language code generation method, apparatus, device, and medium for statistical analysis provided in the embodiments of this disclosure, after acquiring a sample dataset, initial statistical requirement information, and an initial semantic central model, inputs the sample dataset and initial statistical requirement information into the initial semantic central model to obtain multiple sets of initial statistical analysis execution codes corresponding to preset programming languages. Each set of codes is run to obtain corresponding result vectors. Consistency verification is performed based on each result vector, and model repair instructions are generated based on the verification results to update the initial semantic central model, resulting in a target semantic central model. Statistical requirement information is acquired, including a target programming language, which can be any of the preset programming languages. The statistical requirement information is input into the target semantic central model, and the statistical analysis execution code corresponding to the target programming language is output. The embodiments of this disclosure can obtain a semantic central model that can output statistical analysis execution code across languages, thereby enabling the use of user-provided natural languages to provide multiple programming languages and flexibly generate reliable statistical analysis execution code as needed during the statistical analysis process.
[0018] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this disclosure. Attached Figure Description
[0019] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure. It is obvious that the drawings described below are merely some embodiments of this disclosure, and those skilled in the art can obtain other drawings based on these drawings without any inventive effort.
[0020] Figure 1 A flowchart of a semantic hub model training method according to an embodiment of this disclosure is shown; Figure 2 A flowchart of a cross-language statistical analysis execution code generation method according to an embodiment of this disclosure is shown; Figure 3 This diagram illustrates a cross-programming language code generation system architecture according to an embodiment of the present disclosure. Figure 4 A schematic diagram of a dialog interface structure is shown in an embodiment of this disclosure; Figure 5A schematic diagram of another dialog interface structure in an embodiment of this disclosure is shown; Figure 6 This illustration shows a schematic diagram of the structure of a cross-language code generation device for statistical analysis according to an embodiment of the present disclosure; Figure 7 A structural block diagram of an electronic device according to an embodiment of the present disclosure is shown. Detailed Implementation
[0021] Exemplary embodiments will now be described more fully with reference to the accompanying drawings. However, these exemplary embodiments can be implemented in many forms and should not be construed as limited to the examples set forth herein; rather, they are provided so that this disclosure will be more comprehensive and complete, and will fully convey the concept of the exemplary embodiments to those skilled in the art. The described features, structures, or characteristics may be combined in any suitable manner in one or more embodiments.
[0022] Furthermore, the accompanying drawings are merely illustrative of this disclosure and are not necessarily drawn to scale. The same reference numerals in the drawings denote the same or similar parts, and therefore repeated descriptions of them will be omitted. Some block diagrams shown in the drawings are functional entities and do not necessarily correspond to physically or logically independent entities. These functional entities may be implemented in software, in one or more hardware modules or integrated circuits, or in different network and / or processor devices and / or microcontroller devices.
[0023] To facilitate understanding, before introducing the embodiments of this disclosure, the following explanations are provided for several terms involved in the embodiments of this disclosure: SAIR: Statistical Analysis Intermediate Representation.
[0024] AIC: Akaike Information Criterion.
[0025] BIC: Bayesian Information Criterion.
[0026] The specific implementation methods of the embodiments of this disclosure will now be described in detail with reference to the accompanying drawings.
[0027] The overall process of the cross-language code generation method for statistical analysis in this application embodiment can be regarded as two stages. The first stage can be defined as the semantic central model training stage, and the corresponding steps can be summarized as the semantic central model training method. The second stage can be defined as the cross-language statistical analysis execution code generation stage, and the corresponding steps can be summarized as the cross-language statistical analysis execution code generation method.
[0028] Figure 1 A flowchart of a semantic hub model training method according to an embodiment of this disclosure is shown, such as... Figure 1 As shown, the method includes the following steps: S102, obtain the sample dataset, initial statistical requirements information, and initial semantic central model.
[0029] In one embodiment of this disclosure, the sample dataset can be structured data used for sample learning and calibration, the initial statistical requirement information can be statistical requirement information described in natural language, and the initial semantic central model can be an untrained model responsible for unified semantic representation, knowledge fusion, and logical reasoning.
[0030] S104: Input the sample dataset and initial statistical requirements into the initial semantic central model, and map them to obtain multiple sets of initial statistical analysis execution codes corresponding to the preset programming language.
[0031] In one embodiment of this disclosure, the initial semantic central model can map corresponding initial statistical analysis execution code based on the sample dataset and initial statistical requirements. By pre-setting multiple programming languages in the initial semantic central model, multiple sets of corresponding initial statistical analysis execution code can be obtained.
[0032] It should be noted that the preset programming language can be set according to the actual situation, and this embodiment does not impose specific restrictions on it.
[0033] S106, run each set of initial statistical analysis execution code respectively, and obtain the result vector corresponding to each set of initial statistical analysis execution code.
[0034] In one embodiment of this disclosure, each set of initial statistical analysis execution code can be run in parallel within an isolated sandbox to obtain the result vector corresponding to each set of initial statistical analysis execution code. The use of a unified environment parameter (dependency version, random seed, convergence threshold, etc.) within the isolated sandbox ensures reproducibility and supports cross-environment reproduction of the same analysis chain.
[0035] S108 performs a consistency check on each result vector to obtain the consistency check result.
[0036] In one embodiment of this disclosure, the indicators in the result vector can be quantified and compared one by one according to a preset tolerance rule to obtain the consistency verification result.
[0037] S110, if the consistency check result is abnormal, a first model repair instruction is generated to update the initial semantic central model and obtain the target semantic central model.
[0038] As described above, in this embodiment, after obtaining the sample dataset, initial statistical requirements information, and initial semantic central model, the sample dataset and initial statistical requirements information are input into the initial semantic central model. This yields multiple sets of initial statistical analysis execution codes corresponding to a preset programming language. Each set of codes is run to obtain a corresponding result vector. Consistency verification is performed based on each result vector, and model repair instructions are generated based on the verification results to update the initial semantic central model, resulting in the target semantic central model. This embodiment can obtain a semantic central model that can output statistical analysis execution codes across languages. Furthermore, during statistical analysis, multiple programming languages can be provided using user-provided natural languages, and reliable statistical analysis execution codes can be flexibly generated as needed.
[0039] Intermediate representation (IR) in related technologies mainly serves the interoperability between model structure and operator level. It can only solve the problem of consistent computational operations and does not cover the fine-grained conventions of statistical analysis workflow. This is because its expression domain is usually insufficient to bear the precise definitions and constraints of test level, coding method, missing strategies, robust standard error type, information criterion caliber, etc. in social science statistics.
[0040] Furthermore, differences in default settings between statistical software (e.g., dummy variable encoding methods, missing value removal methods, default strategies for weighted and robust clustering, and implementation methods of the Akaike Information Criterion (AIC) / Bayesian Information Criterion (BIC)) directly lead to incomparability between parameter estimates, standard errors, p-values, and the coefficient of determination R² and the information criterion values. In practice, statistical researchers can only rely on their own experience to troubleshoot the causes of errors, which is both inefficient and difficult to trace.
[0041] Based on this, in one embodiment of this disclosure, the above-mentioned S110 includes: inputting the corresponding key semantic parameters in each result vector into the initial semantic central model, automatically generating a first model repair instruction, wherein the first model repair instruction is a model repair instruction obtained after executing difference attribution in a preset order; updating the initial semantic central model based on the first model repair instruction to obtain an updated semantic central model; mapping multiple sets of updated statistical analysis execution codes corresponding to a preset programming language according to the updated semantic central model; running each set of updated statistical analysis execution codes to obtain each updated result vector; performing consistency verification on each updated result vector until the consistency verification result is normal, and obtaining the target semantic central model.
[0042] In one embodiment of this disclosure, multiple backend equivalent statistical analysis execution codes generated by the statistical analysis intermediate representation SAIR (i.e., the aforementioned semantic central model) are run separately in an isolated sandbox, and core statistics, such as coefficients, standard errors, p-values, R², AIC / BIC, etc., are uniformly extracted. Consistency verification is performed using configurable absolute or relative tolerances. If discrepancies are found between results from different programming languages, SAIR performs difference attribution in a predetermined order, such as checking according to missing strategies, coding methods, weight / clustering and robust standard error types, and information criteria. Repair suggestions are automatically generated or patches are directly generated and fed back to SAIR and the corresponding programming language backends, iterating until the preset tolerance is met or an auditable difference report is output. This transforms the consistency verification of code results from empirical judgment to quantitative measurement. By combining isolated parallel execution and configurable tolerance consistency verification with difference attribution and automatic repair in a preset order, an engineering closed loop from problem discovery to location and correction is achieved.
[0043] Among them, the use of an isolated sandbox to unify environmental parameters (dependency version, random seed, convergence threshold, etc.) ensures reproducibility and supports the reproduction of the same analysis link across environments.
[0044] Figure 2 A flowchart of a cross-language statistical analysis execution code generation method according to an embodiment of this disclosure is shown, such as... Figure 2 As shown, the method includes the following steps: S202, Obtain statistical requirement information, which includes: target programming language, which can be any one of the preset programming languages.
[0045] In one embodiment of this disclosure, the statistical requirement information is statistical requirement information described by the user in natural language. The statistical requirement information may include a target programming language, which is used to guide the semantic central model to output its corresponding statistical analysis execution code. The preset programming language is a variety of programming languages for statistical analysis that are pre-set in the semantic central model.
[0046] S204 inputs statistical requirement information into the target semantic central model and outputs the statistical analysis execution code corresponding to the target programming language.
[0047] In one embodiment of this disclosure, the semantic central model can map multiple sets of statistical analysis execution codes corresponding to a preset programming language based on the statistical requirements information provided by the user, and then output the statistical analysis execution code corresponding to the target programming language.
[0048] As described above, in this embodiment, statistical requirement information is first obtained, and then the obtained statistical requirement information is input into a pre-trained semantic central model. The semantic central model can map statistical analysis execution code corresponding to various programming languages. Based on the target programming language contained in the statistical requirement information, the statistical analysis execution code corresponding to that target programming language is output. This embodiment can generate cross-programming language statistical analysis execution code.
[0049] In related technologies, during automatic code repair or program editing, the core is often a single-language abstract syntax tree. This means it can only identify whether the code is written correctly, but lacks the ability to model the domain of statistical analysis semantics. In other words, it cannot recognize specialized terms in the statistical analysis semantic domain and easily interprets them as ordinary code text or syntax fragments. Therefore, when users propose fine-grained modifications such as "adding covariates," "changing robust standard error types," or "switching missing value strategies," the system often rewrites large blocks of code or makes unstable replacements at the text level. This makes it difficult to minimize modifications, ensure cross-language consistency, introduce regression errors, and increase human-machine round-trip costs.
[0050] Based on this, in one embodiment of this disclosure, the method further includes: acquiring new statistical requirement information; parsing the new statistical requirement information to generate a second model repair instruction, wherein the second model repair instruction contains anchor information, including variable anchors, step anchors, or model ID anchors; incrementally updating the corresponding positions of the anchor information in the target semantic central model based on the second model repair instruction; and mapping the updated fragment of the statistical analysis execution code of the corresponding target programming language according to the updated semantic central model.
[0051] It should be noted that the above anchor point information types are only for illustrative purposes and can be adjusted according to actual circumstances. This disclosure does not impose any specific limitations on them.
[0052] In one embodiment of this disclosure, subsequent natural language instructions are parsed as minimal patches for SAIR. These patches are located using anchor information, modify the corresponding positions in SAIR, and are synchronously back-projected into incremental code in the target programming language. That is, a piece of code is generated to replace the part corresponding to the original statistical analysis execution code, rather than rewriting the entire script, thereby ensuring that the modification is controllable, clear and traceable.
[0053] In one embodiment of this disclosure, the method further includes: obtaining irreversible summary information generated during the semantic central model update process, and storing the irreversible summary information locally; wherein the irreversible summary information includes: data fingerprint, version information of the updated semantic central model, patch chain hash, result vector, tolerance parameter and difference attribution record, and the patch chain hash is a hash value generated based on the first model patch instruction and the second model patch instruction.
[0054] In one embodiment of this disclosure, the irreversible digest is a one-way hash that is irreversible, meaning the original string cannot be recovered from the hash value. The irreversible digest in this embodiment may include, but is not limited to, data fingerprints, SAIR version numbers, patch chain hashes, result vectors, tolerance parameters, and difference attribution records. The irreversible digest is written to a local analytics ledger, and the server only processes the computation but does not persist the original data or reversible information. This satisfies privacy compliance while also enabling reproducibility through the local ledger.
[0055] In one embodiment of this disclosure, the method further includes: generating back-translated explanatory text information and key diagnostic summaries based on the consistency verification result and the target semantic central model, wherein the back-translated explanatory text information is used to clarify the update process of the semantic central model; and establishing an association between the key diagnostic summaries and the corresponding back-translated explanatory text information.
[0056] In one embodiment of this disclosure, the iteratively completed SAIR and consistency verification results are translated back into a structured natural language explanation, that is, the technical details are transformed into an explanation that conforms to academic norms and is organized according to fixed logic. Specifically, this may include explanations of variable direction and significance, the rationale for setting weights and cluster robustness, the impact of preset format encoding and reference group selection on result interpretation, and the model goodness comparison criteria of AIC / BIC and the alignment strategy used in this study. A summary of key diagnostics (e.g., pseudo-R², log-likelihood, number of clusters, etc.) should also be attached. The source and rationale for the model specification and diagnostic evidence should be clearly defined to support report writing and review.
[0057] Furthermore, unique identifiers (such as SAIR version numbers or hash values) can be obtained to strongly bind the model update process to the corresponding structured back-translated interpretation, ensuring the authenticity and verifiability of the interpretation. Specifically, interpretations can be associated with code versions, patch chains, and consistency verification records using unique identifiers.
[0058] In one embodiment of this disclosure, the preset programming languages include: R, Python, SPSS, and Stata.
[0059] Specifically, R is an open-source programming language designed specifically for statistical analysis and graphical visualization; Python is a general-purpose programming language commonly used in the field of data science; SPSS is a social science statistics software package, essentially a statistical analysis software suitable for non-programming users; Stata is also essentially a statistical analysis software, a commercial statistical software focused on econometrics and social sciences.
[0060] It should be noted that SPSS and Stata are essentially statistical analysis software, which correspond to operation commands or scripts, rather than programming languages in the general sense.
[0061] In the following specific implementation, taking cross-software consistency alignment using weighted Logit regression (clustering robust standard error) as an example, we demonstrate the complete process of the overall solution based on this application, from natural language to SAIR, multi-backend code generation, parallel execution, consistency verification, and automatic backtracking and patching. Correspondingly, descriptions not covered in the preceding embodiments are also presented as examples.
[0062] The experimental environment for this specific implementation included a Linux x86_64 server, containerized deployment of R, Python 3.10, Stata 17, and SPSS 28; each backend ran in an isolated sandbox, and the random seed was uniformly set to 2025 to avoid repeatability being affected by random factors.
[0063] An example dataset is survey.csv, with an example sample size of approximately 10,000 to 50,000 rows. Specifically, it may include a binary dependent variable y (whether a policy is accepted, 0 / 1), an ordinal independent variable educ (educational level, junior high, high school, undergraduate, or graduate), a numerical independent variable exp (years of work experience), a binary independent variable female (gender, 0 / 1), sampling weights wt, and clustering units pid. Missing data is indicated by NA or -9.
[0064] The user submits an initial statistical analysis request in natural language: use Logit to analyze the relationship between y and educ, exp, and female, use sample weights and cluster robustly on pid, remove missing values by whole case (listwise), report coefficients, standard errors, p-values, R², AIC, BIC, and generate readable interpretations.
[0065] First, the natural language is parsed into the initial semantics of SAIR. Specifically, the variables and measurement levels are defined (educ is ordinal, female is nominal, and exp is numerical), the encoding strategy is set (educ uses ordinal or dummy variable encoding, the reference group is "high school" or set according to user preference), missing data is handled in listwise, weights and clustering are set as wt and pid, the robust standard error type is set to HC1 by default, the model type is logit, and the accompanying diagnostic and information criteria are AIC / BIC.
[0066] Secondly, SAIR maps out executable code for four ends. Specifically, the R end uses glm(...,family=binomial) and vcovHC(type="HC1") to extract cluster robust variance; the Python end uses statsmodels.Logit to fit and gets the robust standard error through get_robustcov_results(cov_type="cluster",cov_kwds={"groups":pid,"use_correction":True}); the Stata end uses logit y x1x2i.educ[pw=wt],vce(cluster pid); and the SPSS end sets WEIGHT BY wt and the equivalent binary logistic procedure.
[0067] The corresponding executable code is run in parallel in four isolated sandboxes, and a result vector is formed by uniformly extracting preset indicators. Specifically, the result vector can be {coef, se, p, r}. 2 , aic, bic}.
[0068] Then, the consistency checker performs tolerance comparison on the result vector generated by the four ends. Specifically, a combined tolerance (the maximum value of the absolute threshold ε_abs and the relative threshold ε_rel·|reference|) is used for the coefficients and standard errors, an absolute tolerance is used for the p-value and R², and a fixed correction is made for the difference in the allowable parameter counting caliber of AIC / BIC.
[0069] In some cases, after initial comparison, the standard errors of some coefficients in R and Stata are out of tolerance, Python and Stata are basically consistent, and SPSS's AIC / BIC have a fixed offset from the other backends. The difference attribution process is performed at the SAIR layer. Specifically, it checks the following in a preset order: missing strategies (confirming all four ends are listwise), encoding methods (ensuring consistent reference groups and encoding methods for the educ), weight / clustering settings (all four ends are based on wt and pid), robustness type (when the R end is explicitly changed from HC3 to HC1, it can be aligned with Stata), and information criterion implementation (differences between SPSS's counting methods and log-likelihood definitions require the addition of correction terms).
[0070] At this point, based on the above-mentioned difference attribution execution results, a patch is automatically generated. Specifically, the robustness type of the R-side is forcibly set to HC1 and cluster=pid is explicitly specified; the reference group of the educ is unified; and a caliber difference description is generated for the SPSS-side AIC / BIC and a correction item is enabled in the validator. After the patch is generated, it is fed back into SAIR and minimized and projected into incremental code for each side. The executable code of the four sides is executed in parallel again, and consistency verification is performed again until the verification passes. The alignment result and the patch chain are then solidified together.
[0071] Finally, the executed SAIR and corresponding results are back-translated and interpreted, i.e., a structured explanation presented in natural language is automatically generated to facilitate team communication and review. Specifically, this may include explanations of variable direction and significance, the rationale for weighting and cluster robustness, the impact of educ encoding and reference group selection on result interpretation, and the alignment strategy of the AIC / BIC model goodness comparison. A key diagnostic summary (e.g., pseudo-R², log-likelihood, number of clusters, etc.) should also be attached.
[0072] Unique identifiers (such as SAIR version numbers or hash values) can be obtained and used to strongly bind the model update process to the corresponding structured back-translated explanations, ensuring the authenticity and verifiability of the explanations. Specifically, explanations can be associated with code versions, patch chains, and consistency verification records using unique identifiers.
[0073] Meanwhile, an irreversible digest (such as data fingerprint, SAIR version number, patch chain hash, result vector, tolerance parameter and difference attribution record, etc.) is obtained and written to the local analysis ledger. The server side only processes the calculations but does not persist the original data or reversible information.
[0074] It should be noted that the initial statistical analysis requirements, sample size and type of the sample dataset, initial semantics in SAIR, and initial configuration of each programming language port are all exemplary only and can be adjusted according to the actual situation. This disclosure does not impose any specific limitations on these aspects.
[0075] The core of this disclosure is to use SAIR as the semantic hub and achieve a closed-loop process "from natural language to multi-backend executable code, from difference discovery to automatic backtracking and repair" through incremental patching and parallel consistency verification, so as to ensure semantic equivalence and comparability of results across multiple statistical analysis programming languages.
[0076] Figure 3 This illustration shows a schematic diagram of a cross-programming language code generation system architecture according to an embodiment of the present disclosure, such as... Figure 3 As shown, the system includes: user 301, dialogue interface 302, natural language parsing module 303, SAIR 304 (i.e., the semantic central model mentioned above), code generator 305 (specifically, including R language code generation port 3051, Python code generation port 3052, SPSS code generation port 3053, Stata code generation port 3054), isolation sandbox 306, result extraction module 307, consistency verification module 308, difference attribution module 309, patch generation module 310, incremental revision engine 311, local analysis ledger 312, and back translation module 313.
[0077] In one embodiment of this disclosure, user 301 inputs a statistical analysis request in natural language form in the dialog interface 302. This request is then converted into structured semantics (i.e., initial SAIR semantics) by the natural language parsing module 303 and input into SAIR 304. Further, the code generator 305 generates four different types of statistical analysis execution code (i.e., ... Figure 3 In the process, the corresponding codes are generated by the R language code generation port 3051, Python code generation port 3052, SPSS code generation port 3053 and Stata code generation port 3054 respectively, and run in parallel in the isolation sandbox 306. The running results are sent to the result extraction module 307 to uniformly extract the preset core statistics as the result vector.
[0078] The obtained result vector is sent to the consistency verification module 308. According to the tolerance comparison result, if the tolerance is exceeded, the difference attribution module 309 is triggered to execute the difference attribution process. The patch generation module 310 automatically generates a repair suggestion or directly generates a patch, and then feeds it back to SAIR 304 through the incremental revision engine 311.
[0079] When user 301 inputs additional statistical analysis requests in natural language form through the dialog interface 302, the incremental revision engine 311 parses them into structured editing operations (such as insertion, deletion, modification, etc.) for SAIR or domain-enhanced abstract syntax tree AST, forms a patch chain with variables, steps, or model IDs as anchors, and sends it to SAIR 304. This allows the patch to be projected onto each backend code with minimal changes, modifying only the code segments necessary to implement semantic changes, rather than rewriting the entire code.
[0080] Based on this Figure 4 A schematic diagram of a dialog interface structure according to an embodiment of this disclosure is shown. Figure 5 Another schematic diagram of a dialog interface structure in an embodiment of this disclosure is shown, such as... Figure 4 and Figure 5 As shown, the dialog interface is the front-end interactive interface.
[0081] The left-hand dialog area displays guiding text (providing examples of analytical scenarios, such as descriptive statistical analysis, correlation analysis, regression analysis, t-tests, ANOVA, and data visualization), examples, and prompts. It also provides interactive buttons for dialog history and creating new dialogs. The bottom features a user text input box and a dropdown menu for switching between different programming languages, supporting R, Python, SPSS, and Stata—four programming languages / software suitable for statistical analysis.
[0082] The right-hand dialog area is divided into two tabs: source code and execution results, both of which are initially blank. In addition, it provides operation buttons such as copy, clear, run, and full screen to facilitate user management and execution of code.
[0083] It should be noted that the above-mentioned dialog interface example is only for illustrative purposes. The interface style, prompts, programming language, operation functions, etc. can be adjusted according to the actual situation, and this disclosure does not impose any specific limitations on them.
[0084] In addition, the local analysis ledger 312 is used to store irreversible summary information, such as data fingerprints, SAIR version numbers, patch chain hashes, result vectors, tolerance parameters, and difference attribution records, to ensure privacy and reproducibility. The back-translation module 313 is used to transform SAIR, code, and results into readable structured explanations, clarifying model settings, coding and reference groups, robust selection of weights / clustering, and diagnostic and caliber descriptions. It also strongly binds the explanations to the corresponding code versions, patch chains, and consistency verification records to support review and external reporting.
[0085] This disclosure proposes SAIR, which realizes and structures the key semantics in the field of statistical analysis, and establishes a bidirectional mapping with various programming languages / software related to statistical analysis. This enables the process of "natural language → SAIR → multiple backend codes" and "code → SAIR (back translation)", which greatly reduces the inconsistency and non-reproducibility of cross-language programming from the source.
[0086] Based on the same inventive concept, this disclosure also provides a cross-language code generation device for statistical analysis, as shown in the following embodiment. Since the principle by which this device embodiment solves the problem is similar to that of the above-described method embodiment, the implementation of this device embodiment can refer to the implementation of the above-described method embodiment, and repeated details will not be elaborated further.
[0087] Figure 6 A schematic diagram of a cross-language code generation device for statistical analysis, as shown in an embodiment of this disclosure, is illustrated. Figure 6 As shown, the device includes: an initial information acquisition module 601, an initial execution code generation module 602, a result vector calculation module 603, a consistency verification module 604, a first semantic central model update module 605, a statistical requirement information acquisition module 606, and a statistical analysis execution code generation module 607.
[0088] The system comprises the following modules: an initial information acquisition module 601, used to acquire sample datasets, initial statistical requirements information, and an initial semantic central model; an initial execution code generation module 602, used to input the sample datasets and initial statistical requirements information into the initial semantic central model, mapping them to multiple sets of initial statistical analysis execution codes corresponding to preset programming languages; a result vector calculation module 603, used to run each set of initial statistical analysis execution codes to obtain result vectors corresponding to each set of initial statistical analysis execution codes; a consistency verification module 604, used to perform consistency verification on each result vector to obtain a consistency verification result; a first semantic central model update module 605, used to generate a first model repair instruction to update the initial semantic central model if the consistency verification result is abnormal, to obtain a target semantic central model; a statistical requirements information acquisition module 606, used to acquire statistical requirements information, including a target programming language, which can be any one of the preset programming languages; and a statistical analysis execution code generation module 607, used to input the statistical requirements information into the target semantic central model and output the statistical analysis execution code corresponding to the target programming language.
[0089] As described above, in this embodiment, after obtaining the sample dataset, initial statistical requirements information, and initial semantic central model, the sample dataset and initial statistical requirements information are input into the initial semantic central model. This yields multiple sets of initial statistical analysis execution codes corresponding to a preset programming language. Each set of codes is run to obtain a corresponding result vector. Consistency verification is performed based on each result vector, and model repair instructions are generated based on the verification results to update the initial semantic central model, resulting in the target semantic central model. This embodiment can obtain a semantic central model that can output statistical analysis execution codes across languages. Furthermore, during statistical analysis, multiple programming languages can be provided using user-provided natural languages, and reliable statistical analysis execution codes can be flexibly generated as needed.
[0090] In one embodiment of this disclosure, the semantic central model update module 605 is further configured to input the corresponding key semantic parameters in each result vector into the initial semantic central model, automatically generate a first model repair instruction, wherein the first model repair instruction is a model repair instruction obtained after executing difference attribution in a preset order; based on the first model repair instruction, update the initial semantic central model to obtain an updated semantic central model; according to the updated semantic central model, map multiple sets of updated statistical analysis execution codes corresponding to a preset programming language; run each set of updated statistical analysis execution codes to obtain each updated result vector; perform consistency verification on each updated result vector until the consistency verification result is normal, and obtain the target semantic central model.
[0091] In one embodiment of this disclosure, the apparatus further includes: a second semantic central model update module, used to acquire new statistical requirement information; parse the new statistical requirement information to generate a second model repair instruction, wherein the second model repair instruction includes anchor information, including variable anchors, step anchors, or model ID anchors; incrementally update the corresponding positions of the anchor information in the target semantic central model based on the second model repair instruction; and map the updated fragment of the statistical analysis execution code of the corresponding target programming language according to the updated semantic central model.
[0092] In one embodiment of this disclosure, the apparatus further includes: a summary information generation module, used to obtain irreversible summary information generated during the semantic central model update process, and store the irreversible summary information locally; wherein, the irreversible summary information includes: data fingerprint, version information of the updated semantic central model, patch chain hash, result vector, tolerance parameter and difference attribution record, and the patch chain hash is a hash value generated based on the first model patch instruction and the second model patch instruction.
[0093] In one embodiment of this disclosure, the apparatus further includes: a back-translation information generation module, used to generate back-translation explanation text information and key diagnostic summaries based on the consistency verification result and the target semantic central model, wherein the back-translation explanation text information is used to clarify the update process of the semantic central model; and to establish an association between the key diagnostic summaries and the corresponding back-translation explanation text information.
[0094] In one embodiment of this disclosure, the second model repair instruction corresponds to at least one structured editing operation among insertion, deletion, and modification.
[0095] In one embodiment of this disclosure, the preset programming languages include: R, Python, SPSS, and Stata.
[0096] Those skilled in the art will understand that various aspects of this disclosure can be implemented as a system, method, or program product. Therefore, various aspects of this disclosure can be specifically implemented in the following forms: a completely hardware implementation, a completely software implementation (including firmware, microcode, etc.), or a combination of hardware and software aspects, collectively referred to herein as a "circuit," "module," or "system."
[0097] The following reference Figure 7 To describe an electronic device 700 according to such an embodiment of the present disclosure. Figure 7 The electronic device 700 shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments disclosed herein.
[0098] like Figure 7 As shown, the electronic device 700 is manifested in the form of a general-purpose computing device. The components of the electronic device 700 may include, but are not limited to: at least one processing unit 710, at least one storage unit 720, and a bus 730 connecting different system components (including storage unit 720 and processing unit 710).
[0099] The storage unit stores program code, which can be executed by the processing unit 710, causing the processing unit 710 to perform the steps described in the "Exemplary Methods" section of this specification according to various exemplary embodiments of this disclosure. For example, the processing unit 710 can perform the following steps of the above method embodiments: acquiring a sample dataset, initial statistical requirement information, and an initial semantic central model; inputting the sample dataset and initial statistical requirement information into the initial semantic central model, mapping to obtain multiple sets of initial statistical analysis execution codes corresponding to a preset programming language; running each set of initial statistical analysis execution codes respectively, obtaining result vectors corresponding to each set of initial statistical analysis execution codes; performing consistency verification on each result vector, obtaining consistency verification results; if the consistency verification results are abnormal, generating a first model repair instruction to update the initial semantic central model, obtaining a target semantic central model.
[0100] Storage unit 720 may include readable media in the form of volatile storage units, such as random access memory (RAM) 7201 and / or cache memory 7202, and may further include read-only memory (ROM) 7203.
[0101] The storage unit 720 may also include a program / utility 7204 having a set (at least one) program module 7205, such program module 7205 including but not limited to: an operating system, one or more application programs, other program modules and program data, each or some combination of these examples may include an implementation of a network environment.
[0102] Bus 730 can represent one or more of several types of bus structures, including a memory cell bus or memory cell controller, a peripheral bus, a graphics acceleration port, a processing unit, or a local bus using any of the various bus structures.
[0103] Electronic device 700 can also communicate with one or more external devices 740 (e.g., keyboard, pointing device, Bluetooth device, etc.), and with one or more devices that enable a user to interact with electronic device 700, and / or with any device that enables electronic device 700 to communicate with one or more other computing devices (e.g., router, modem, etc.). This communication can be performed via input / output (I / O) interface 750. Furthermore, electronic device 700 can also communicate with one or more networks (e.g., local area network (LAN), wide area network (WAN), and / or public networks, such as the Internet) via network adapter 760. As shown, network adapter 760 communicates with other modules of electronic device 700 via bus 730. It should be understood that, although not shown in the figures, other hardware and / or software modules can be used in conjunction with electronic device 700, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0104] From the above description of the embodiments, those skilled in the art will readily understand that the exemplary embodiments described herein can be implemented by software or by combining software with necessary hardware. Therefore, the technical solutions according to the embodiments of this disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (such as a CD-ROM, USB flash drive, external hard drive, etc.) or on a network, including several instructions to cause a computing device (such as a personal computer, server, terminal device, or network device, etc.) to execute the methods according to the embodiments of this disclosure.
[0105] Based on the same inventive concept, this disclosure also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements any of the above-described methods for cross-language code generation oriented towards statistical analysis. Since the principle by which this computer-readable storage medium addresses the problem is similar to that of the above-described method embodiments, the implementation of this computer-readable storage medium embodiment can refer to the implementation of the above-described method embodiments, and repeated details will not be elaborated further.
[0106] More specific examples of computer-readable storage media in this disclosure may include, but are not limited to: electrical connections having one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0107] In this disclosure, a computer-readable storage medium may include a data signal propagated in baseband or as part of a carrier wave, carrying readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A readable signal medium may also be any readable medium other than a readable storage medium, capable of transmitting, propagating, or transmitting a program for use by or in connection with an instruction execution system, apparatus, or device.
[0108] Optionally, the program code contained on the computer-readable storage medium may be transmitted using any suitable medium, including but not limited to wireless, wired, optical fiber, RF, etc., or any suitable combination thereof.
[0109] In practical implementation, program code for performing the operations of this disclosure can be written in any combination of one or more programming languages, including object-oriented programming languages such as Java and C++, and conventional procedural programming languages such as C or similar languages. The program code can execute entirely on the user's computing device, partially on the user's device, as a standalone software package, partially on the user's computing device and partially on a remote computing device, or entirely on a remote computing device or server. In cases involving remote computing devices, the remote computing device can be connected to the user's computing device via any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computing device (e.g., via the Internet using an Internet service provider).
[0110] It should be noted that although several modules or units for the device used to perform actions have been mentioned in the detailed description above, this division is not mandatory. In fact, according to embodiments of this disclosure, the features and functions of two or more modules or units described above can be embodied in one module or unit. Conversely, the features and functions of one module or unit described above can be further divided and embodied by multiple modules or units.
[0111] Furthermore, although the steps of the method in this disclosure are described in a specific order in the accompanying drawings, this does not require or imply that the steps must be performed in that specific order, or that all the steps shown must be performed to achieve the desired result. Additional or alternative steps may be omitted, multiple steps may be combined into one step, and / or a step may be broken down into multiple steps.
[0112] From the above description of the embodiments, those skilled in the art will readily understand that the exemplary embodiments described herein can be implemented by software or by combining software with necessary hardware. Therefore, the technical solutions according to the embodiments of this disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (such as a CD-ROM, USB flash drive, external hard drive, etc.) or on a network, including several instructions to cause a computing device (such as a personal computer, server, mobile terminal, or network device, etc.) to execute the methods according to the embodiments of this disclosure.
[0113] Other embodiments of this disclosure will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This disclosure is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this disclosure are indicated by the appended claims.
Claims
1. A cross-language code generation method for statistical analysis, characterized in that, include: Acquire sample datasets, initial statistical requirements, and an initial semantic central model; The sample dataset and the initial statistical requirements information are input into the initial semantic central model, and multiple sets of initial statistical analysis execution codes corresponding to a preset programming language are mapped to obtain the following: Run each set of initial statistical analysis execution code separately to obtain the result vector corresponding to each set of initial statistical analysis execution code; Perform a consistency check on each result vector to obtain the consistency check result; If the consistency check result is abnormal, a first model repair instruction is generated to update the initial semantic central model, thereby obtaining the target semantic central model; Obtain statistical requirement information, wherein the statistical requirement information includes: target programming language, which is any one of the preset programming languages; The statistical requirement information is input into the target semantic central model, and the statistical analysis execution code corresponding to the target programming language is output. The step of generating a first model repair instruction to update the initial semantic central model and obtain a target semantic central model includes: inputting the corresponding key semantic parameters from each result vector into the initial semantic central model; automatically generating a first model repair instruction, wherein the first model repair instruction is a model repair instruction obtained after executing difference attribution in a preset order; updating the initial semantic central model based on the first model repair instruction to obtain an updated semantic central model; mapping multiple sets of updated statistical analysis execution codes corresponding to a preset programming language according to the updated semantic central model; running each set of updated statistical analysis execution codes to obtain each updated result vector; and performing consistency verification on each updated result vector until the consistency verification result is normal, thereby obtaining the target semantic central model. The method further includes: acquiring new statistical requirement information; parsing the new statistical requirement information to generate a second model repair instruction, wherein the second model repair instruction contains anchor information, including variable anchors, step anchors, or model ID anchors; incrementally updating the corresponding positions of the anchor information in the target semantic central model based on the second model repair instruction; and mapping the updated fragment of the statistical analysis execution code of the corresponding target programming language according to the updated semantic central model. The method further includes: obtaining irreversible summary information generated during the semantic central model update process, and storing the irreversible summary information locally; wherein the irreversible summary information includes: data fingerprint, version information of the updated semantic central model, patch chain hash, result vector, tolerance parameter and difference attribution record, and the patch chain hash is a hash value generated based on the first model patch instruction and the second model patch instruction.
2. The cross-language code generation method for statistical analysis according to claim 1, characterized in that, The method further includes: Based on the consistency verification results and the target semantic central model, back-translated explanatory text information and key diagnostic summaries are generated. The back-translated explanatory text information is used to clarify the update process of the semantic central model. Establish a correlation between the key diagnostic summary and the corresponding back-translated explanatory text information.
3. The cross-language code generation method for statistical analysis according to claim 1, characterized in that, The second model repair instruction corresponds to at least one structured editing operation among insertion, deletion, and modification.
4. The cross-language code generation method for statistical analysis according to claim 1, characterized in that, The default programming languages include: R, Python, SPSS, and Stata.
5. A cross-language code generation device for statistical analysis, characterized in that, include: The initial information acquisition module is used to acquire the sample dataset, initial statistical requirements information, and initial semantic central model; The initial execution code generation module is used to input the sample dataset and the initial statistical requirements information into the initial semantic central model, and map them to obtain multiple sets of initial statistical analysis execution codes corresponding to a preset programming language; The result vector calculation module is used to run each set of initial statistical analysis execution code separately and obtain the result vector corresponding to each set of initial statistical analysis execution code. The consistency verification module is used to perform consistency verification on each result vector and obtain the consistency verification result. The semantic central model update module is used to generate a first model repair instruction to update the initial semantic central model if the consistency check result is abnormal, so as to obtain the target semantic central model. The statistical requirement information acquisition module is used to acquire statistical requirement information, which includes: target programming language, which can be any one of the preset programming languages; The statistical analysis execution code generation module is used to input statistical requirement information into the target semantic central model and output the statistical analysis execution code corresponding to the target programming language. The semantic central model update module is further configured to input the corresponding key semantic parameters from each result vector into the initial semantic central model, automatically generate a first model repair instruction, wherein the first model repair instruction is a model repair instruction obtained after executing difference attribution in a preset order; update the initial semantic central model based on the first model repair instruction to obtain an updated semantic central model; map multiple sets of updated statistical analysis execution codes corresponding to a preset programming language according to the updated semantic central model; run each set of updated statistical analysis execution codes to obtain each updated result vector; perform consistency verification on each updated result vector until the consistency verification result is normal, and obtain the target semantic central model. The device further includes: a second semantic central model update module, used to acquire new statistical requirement information; parse the new statistical requirement information to generate a second model repair instruction, wherein the second model repair instruction contains anchor information, including variable anchors, step anchors, or model ID anchors; incrementally update the corresponding positions of the anchor information in the target semantic central model based on the second model repair instruction; and map the updated fragment of the statistical analysis execution code of the corresponding target programming language according to the updated semantic central model. The device further includes: a summary information generation module, used to acquire irreversible summary information generated during the semantic central model update process, and store the irreversible summary information locally; wherein the irreversible summary information includes: data fingerprint, version information of the updated semantic central model, patch chain hash, result vector, tolerance parameter and difference attribution record, and the patch chain hash is a hash value generated based on the first model patch instruction and the second model patch instruction.
6. An electronic device, characterized in that, include: processor; as well as Memory is used to store the processor's executable instructions; The processor is configured to execute the cross-language code generation method for statistical analysis according to any one of claims 1 to 4 by executing executable instructions.
7. A computer-readable storage medium having a computer program stored thereon, characterized in that, When a computer program is executed by a processor, it implements the cross-language code generation method for statistical analysis as described in any one of claims 1 to 4.
Citation Information
Patent Citations
Multi-modal fusion intelligent question answering and knowledge retrieval method and system
CN121119172A
Multi-language code generation method based on self-supervised pre-training
CN121143762A