CN117971236B - Operator analysis method, device, equipment and medium based on lexical and grammatical analysis - Google Patents

Operator analysis method, device, equipment and medium based on lexical and grammatical analysis Download PDF

Info

Publication number
CN117971236B
CN117971236B CN202410380906.4A CN202410380906A CN117971236B CN 117971236 B CN117971236 B CN 117971236B CN 202410380906 A CN202410380906 A CN 202410380906A CN 117971236 B CN117971236 B CN 117971236B
Authority
CN
China
Prior art keywords
operator
analysis
basic
parsing
complex
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202410380906.4A
Other languages
Chinese (zh)
Other versions
CN117971236A (en
Inventor
侯博川
吴韶华
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Inspur Electronic Information Industry Co Ltd
Original Assignee
Inspur Electronic Information Industry Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Inspur Electronic Information Industry Co Ltd filed Critical Inspur Electronic Information Industry Co Ltd
Priority to CN202410380906.4A priority Critical patent/CN117971236B/en
Publication of CN117971236A publication Critical patent/CN117971236A/en
Application granted granted Critical
Publication of CN117971236B publication Critical patent/CN117971236B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Machine Translation (AREA)

Abstract

The application discloses an operator analysis method, device, equipment and medium based on lexical and grammatical analysis, and relates to the technical field of artificial intelligence. The method comprises the following steps: acquiring complex operator requirements to be realized from an artificial intelligent model and/or a deep learning algorithm framework, and determining a target complex operator to be analyzed according to the complex operator requirements; acquiring a first analysis rule predefined by the lexical analyzer, and analyzing a character string corresponding to the target complex operator into morphemes according to the first analysis rule; acquiring a second parsing rule predefined by the grammar parser, and converting morphemes corresponding to the target complex operator into corresponding tree-shaped structures according to the second parsing rule; and analyzing the target complex operator into a corresponding basic operator according to the tree structure body so as to obtain a calculation result corresponding to the target complex operator based on the basic operator obtained after analysis. By the technical scheme, the complex operator can be automatically analyzed, and the development efficiency is effectively improved.

Description

Operator analysis method, device, equipment and medium based on lexical and grammatical analysis
Technical Field
The invention relates to the technical field of artificial intelligence, in particular to an operator analysis method, an operator analysis device, operator analysis equipment and operator analysis medium based on lexical and grammatical analysis.
Background
In recent years, the development heat of artificial intelligence (ARTIFICIAL INTELLIGENCE, AI) is continuously rising, and technology is increasingly updated and iterated. Among them, the deep learning algorithm is considered as a key to promote the development of artificial intelligence. The deep learning algorithm is made up of computational units, which may also be referred to as operators. In computer programming, an operator is a function or operator that performs a particular operation. To ensure that AI chips can handle increasingly complex operator tasks, developers must choose a programming language compatible with the chip and carefully design and implement the corresponding programming code in terms of complex operator-specific mathematical logic, typically involving defining new operators or optimizing existing operators. The most common method at present is to manually write each new operator, and the development cost is high and the efficiency is low.
Therefore, how to automatically generate operator codes corresponding to complex operators to improve development efficiency and maintainability of codes, and reducing the workload of manual writing and maintenance are problems that are needed to be solved by those skilled in the art at present.
Disclosure of Invention
In view of the above, the present invention aims to provide an operator analysis method, device, equipment and medium based on lexical and grammatical analysis, which can automatically analyze complex operators into basic operators for development, and reduce the workload of manual writing and maintenance by automatically generating operator codes. The specific scheme is as follows:
In a first aspect, the application discloses an operator parsing method based on lexical and grammatical analysis, comprising the following steps:
Acquiring complex operator requirements to be realized from an artificial intelligent model and/or a deep learning algorithm framework, and determining a target complex operator to be analyzed according to the complex operator requirements; the complex operator requirement is a requirement of analyzing the complex operator into a basic operator, wherein the basic operator is an operator used for single operation, and the complex operator is an operator obtained by combining at least two basic operators;
Acquiring a first analysis rule predefined by a lexical analyzer, and analyzing a character string corresponding to the target complex operator into morphemes according to the first analysis rule;
Acquiring a second parsing rule predefined by a grammar parser, and converting morphemes corresponding to the target complex operator into corresponding tree-shaped structures according to the second parsing rule;
And analyzing the target complex operator into a corresponding basic operator according to the tree structure body so as to obtain a calculation result corresponding to the target complex operator based on the basic operator obtained after analysis.
Optionally, after determining the target complex operator to be resolved according to the complex operator requirement, the method further includes:
Analyzing and recording the target complex operator as a corresponding first mathematical expression so as to determine a character string corresponding to the target complex operator according to the first mathematical expression;
constructing a data management file with a preset data format, and managing a character string corresponding to the target complex operator through the data management file;
correspondingly, the obtaining the first parsing rule predefined by the lexical analyzer, and parsing the character string corresponding to the target complex operator into morphemes according to the first parsing rule includes:
determining a character string corresponding to the target complex operator from the data management file;
And acquiring a first analysis rule predefined by the lexical analyzer, and analyzing the character string into morphemes according to the first analysis rule.
Optionally, before determining the character string corresponding to the target complex operator from the data management file, the method further includes:
calling a first preset interface to acquire a second mathematical expression of the basic operator in the data management file;
And calling a second preset interface to judge whether a missing basic operator exists in the data management file and/or whether each basic operator is analyzed or not according to the first mathematical expression and the second mathematical expression.
Optionally, the method for parsing operators based on lexical and grammatical analysis further includes:
If a new access artificial intelligent model and/or a deep learning algorithm frame exist currently, determining a corresponding new operator development requirement according to the new access artificial intelligent model and/or the deep learning algorithm frame;
And determining a target operator which does not exist in the data management file according to the new operator development requirement and the complex operator requirement, and adding the target operator to the data management file.
Optionally, the method for parsing operators based on lexical and grammatical analysis further includes:
Acquiring regular expression definitions, data structure definitions and auxiliary function declarations; the regular expression definition is used for generating a preset regular matching rule for decomposing the character strings corresponding to the target complex operator; the data structure defines a structure body for generating and storing the basic operator; the auxiliary function declaration is used for defining functions except functions declared by the lexical analyzer and the grammar analyzer;
and constructing an auxiliary file based on the regular expression definition, the data structure definition and the auxiliary function statement so as to execute the operator analysis method based on the lexical and grammatical analysis based on the auxiliary file.
Optionally, after the morpheme corresponding to the target complex operator is converted into the corresponding tree structure body according to the second parsing rule, the method further includes:
storing the tree structure body according to the data structure definition in the auxiliary file, and judging whether a lacking basic operator exists in the tree structure body;
if the missing base operator exists in the tree structure, the missing base operator is directly added to the data management file.
Optionally, after obtaining the complex operator requirement to be implemented from the artificial intelligence model and/or the deep learning algorithm framework and determining the target complex operator to be resolved according to the complex operator requirement, the method further includes:
And calling a third preset interface, and carrying out standardization regularization on the name character string and the data which are correspondingly input by the target complex operator so as to obtain corresponding standardization expression characters.
Optionally, the parsing the character string corresponding to the target complex operator into morphemes according to the first parsing rule includes:
Decomposing the character strings corresponding to the target complex operators by using a preset regular matching rule to obtain a plurality of decomposed characters;
Matching the decomposed character with the recognition character to analyze the character string corresponding to the target complex operator into morphemes; wherein the identification character is a character with an output mark set.
Optionally, the converting, according to the second parsing rule, the morpheme corresponding to the target complex operator into a corresponding tree structure body includes:
and sequentially determining node structures corresponding to the morphemes based on a preset analysis sequence and by utilizing a generation type, and generating the tree structure based on the node structures.
Optionally, the method for parsing operators based on lexical and grammatical analysis further includes:
and detecting the mathematical expression of the operator by using the lexical analyzer and/or the grammar analyzer, and prompting the mathematical expression errors and anomalies of the operator found in the detection process.
Optionally, the method for parsing operators based on lexical and grammatical analysis further includes:
If operator development requirements only realized through the basic operators exist at present, determining a target basic operator corresponding to the operator development requirements, and preprocessing the target basic operator according to the data management file to obtain a processed character string;
constructing a fourth preset interface for inputting operator codes of the target basic operator, and acquiring a first operator code of the target basic operator through the fourth preset interface;
and calculating the target basic operator based on the first operator code to obtain a corresponding calculation result.
Optionally, the parsing the target complex operator into a corresponding basic operator according to the tree structure body so as to calculate based on the basic operator obtained after parsing to obtain a calculation result corresponding to the target complex operator, including:
Calling each node in the tree structure body through a fifth preset interface to traverse the tree structure body to obtain a second operator code corresponding to the basic operator obtained after analysis;
And calculating the target complex operator based on the second operator code to obtain a corresponding calculation result.
In a second aspect, the application discloses an operator parsing device based on lexical and grammatical analysis, comprising:
The demand extraction module is used for acquiring complex operator demands to be realized from the artificial intelligent model and/or the deep learning algorithm framework, and determining target complex operators to be analyzed according to the complex operator demands; the complex operator requirement is a requirement of analyzing the complex operator into a basic operator, wherein the basic operator is an operator used for single operation, and the complex operator is an operator obtained by combining a plurality of basic operators;
the first analysis module is used for acquiring a first analysis rule predefined by the lexical analyzer and analyzing the character string corresponding to the target complex operator into morphemes according to the first analysis rule;
the second analysis module is used for acquiring a second analysis rule predefined by the grammar analyzer and converting morphemes corresponding to the target complex operator into corresponding tree-shaped structures according to the second analysis rule;
and the operator analysis module is used for analyzing the target complex operator into a corresponding basic operator according to the tree structure body so as to obtain a calculation result corresponding to the target complex operator based on the basic operator obtained after analysis.
In a third aspect, the present application discloses an electronic device, comprising:
a memory for storing a computer program;
A processor for loading and executing the computer program to implement the steps of the lexical and grammatical analysis based operator parsing method as described above.
In a fourth aspect, the present application discloses a computer-readable storage medium for storing a computer program; wherein the computer program when executed by a processor implements an operator parsing method based on lexical and grammatical analysis as described above.
The application provides an operator analysis method based on lexical and grammatical analysis, which comprises the following steps: acquiring complex operator requirements to be realized from an artificial intelligent model and/or a deep learning algorithm framework, and determining a target complex operator to be analyzed according to the complex operator requirements; the complex operator requirement is a requirement of analyzing the complex operator into a basic operator, wherein the basic operator is an operator used for single operation, and the complex operator is an operator obtained by combining at least two basic operators; acquiring a first analysis rule predefined by a lexical analyzer, and analyzing a character string corresponding to the target complex operator into morphemes according to the first analysis rule; acquiring a second parsing rule predefined by a grammar parser, and converting morphemes corresponding to the target complex operator into corresponding tree-shaped structures according to the second parsing rule; and analyzing the target complex operator into a corresponding basic operator according to the tree structure body so as to obtain a calculation result corresponding to the target complex operator based on the basic operator obtained after analysis.
The beneficial technical effects of the application are as follows: for the development requirements of multiple complex operators of multiple AI models and deep learning algorithm frameworks, automatic parsing of the target complex operator into the base operator is achieved by using a lexical analyzer and a grammar analyzer. Meanwhile, according to the analysis rule of the complex operator, the input of multiple types of complex operators can be processed and analyzed into corresponding basic operators, and the method has good usability and expandability. When the operator analysis code is automatically generated based on a tree structure body formed by a plurality of basic operators for development, not only the workload of manual writing and maintenance can be reduced, but also errors can be reduced, better maintainability can be provided, and the code can adapt to the continuously updated AI chip and multi-chip environment. Therefore, the development efficiency is effectively improved, and the development cost is reduced.
In addition, the operator analysis device, the device and the storage medium based on the lexical and grammatical analysis correspond to the operator analysis method based on the lexical and grammatical analysis, and have the same effects.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings that are required to be used in the embodiments or the description of the prior art will be briefly described below, and it is obvious that the drawings in the following description are only embodiments of the present invention, and that other drawings can be obtained according to the provided drawings without inventive effort for a person skilled in the art.
FIG. 1 is a flow diagram of a complex operator development function implemented in a prior art solution;
FIG. 2 is a flow chart of an operator parsing method based on lexical and grammatical analysis in accordance with the present application;
FIG. 3 is a schematic flow chart of Flex and Bison implementation operator resolution disclosed by the application;
FIG. 4 is a flowchart of a specific method for parsing operators based on lexical and grammatical analysis according to the present disclosure;
FIG. 5 is a schematic diagram illustrating the resolution of a complex operator atanh disclosed in the present application;
FIG. 6 is a schematic diagram of an operator parsing system based on lexical and grammatical analysis in accordance with the present disclosure;
FIG. 7 is a schematic diagram of an operator parsing apparatus based on lexical and grammatical analysis according to the present disclosure;
fig. 8 is a block diagram of an electronic device according to the present disclosure.
Detailed Description
The following description of the embodiments of the present invention will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present invention, but not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
With the rapid development of artificial intelligence models and deep learning algorithms, the mathematical logic and complexity of operators is also gradually rising. Currently, the development of complex operators in computer programming typically involves defining new operators or optimizing existing operators. Meanwhile, based on AI models of different chips, operator development tasks are not completely the same, and adaptability of complex operators is limited. A schematic flow diagram for implementing complex operator development is provided in an exemplary manner as shown in fig. 1. For complex operator requirements to be implemented in the artificial intelligence model/deep learning algorithm framework, the most common methods in the prior art include either direct complex operator development or manual writing of parsers. For the situation that complex operators do not need to be analyzed to directly develop the complex operators, the operators in the requirement list need to be developed in sequence to realize functions; for the case that a parser is manually written for a complex operator to be parsed, if the complex operator is parsed for the first time, a parsing code is written according to a specific operator grammar rule when the parser is designed so as to convert the complex operator into a basic operator; if the complex operator is analyzed for the first time, whether the existing analyzer meets the requirement is further judged, and when the existing analyzer does not meet the requirement, the re-development is needed for the analyzer; the operator development implementation functions can be performed with the existing resolvers only when the existing resolvers meet the requirements. At present, the development work of complex operators based on an AI model has the following problems:
(1) Many complex operators exist in the latest deep learning algorithm framework, including a large number of matrix operations, activation functions, convolution operations and the like, and the complex operators have higher complexity, require a large amount of labor and time cost for direct development, and are easy to make mistakes or generate loopholes;
(2) Software operators need to be updated frequently to maintain flexibility and need to be updated in large numbers in time. The code habits of different developers are different, and the subsequent maintenance cost is high;
(3) The code developed manually has low expandability, and not only needs to consume a great deal of time to maintain the same code development standard, but also faces great challenges in meeting the adaptation requirements of multiple chip multi-class complex operators.
Therefore, the application provides an operator analysis scheme based on lexical and grammatical analysis, which can automatically generate corresponding operator codes aiming at complex operators, reduce the workload of manual writing and maintenance and improve the development efficiency and the maintainability of codes.
The first embodiment of the operator parsing method based on lexical and grammatical analysis provided by the present invention is described in detail below, and referring to fig. 2, the method includes:
Step S11: acquiring complex operator requirements to be realized from an artificial intelligent model and/or a deep learning algorithm framework, and determining a target complex operator to be analyzed according to the complex operator requirements; the complex operator requirement is a requirement of analyzing the complex operator into a basic operator, wherein the basic operator is an operator for single operation, and the complex operator is an operator obtained by combining at least two basic operators.
Currently, artificial intelligence chips are finding application in more and more scenarios, and can be used exclusively for processing a large number of computational tasks in artificial intelligence applications, where these processes typically require more complex operators, thereby consuming larger computational resources. Therefore, aiming at operator development tasks under different application scenes, if automatic analysis of complex operators can be realized, and then operator codes are generated by developing the complex operators, the development efficiency can be greatly improved.
In the embodiment of the application, an operator analysis method based on lexical and grammatical analysis is provided under an artificial intelligence framework. First, complex operator requirements to be implemented are obtained from artificial intelligence models and/or deep learning algorithm frameworks. The complex operator requirement is a requirement of resolving the complex operator into a basic operator, that is, a complex operator automatic resolving task which needs to be realized.
Notably, the base operator is an operator for performing a single operation, such as log (natural logarithm), addition, subtraction, division, and the like; complex operators are operators obtained by combining at least two of said basis operators, for example atanh (x) =log ((1+x)/(1-x))/2.
After the complex operator requirements to be realized are extracted from the artificial intelligent model and/or the deep learning algorithm framework, determining the target complex operator to be analyzed according to the complex operator requirements. It can be understood that, aiming at the development requirement of the target complex operator, the corresponding name character string and data need to be input, so as to complete the automatic analysis. In the embodiment of the application, the input corresponding to the target complex operator is normalized and regularized aiming at the input of the target complex operator. Specifically, a third preset interface is called, and normalized regularization is carried out on the name character string and the data which are correspondingly input by the target complex operator, so that corresponding normalized expression characters are obtained.
Illustratively, for complex operator Atanh, call getRegex () interface is canonical regularized so that whether "ATANH", "Atanh", "Atanh" or "Atanh (x)" is entered, it ultimately points to operator Atanh. Thus, not only can the data redundancy be reduced, but also the recognition efficiency can be improved.
Step S12: and acquiring a first analysis rule predefined by the lexical analyzer, and analyzing the character string corresponding to the target complex operator into morphemes according to the first analysis rule.
Step S13: and acquiring a second parsing rule predefined by the grammar analyzer, and converting morphemes corresponding to the target complex operator into corresponding tree structures according to the second parsing rule.
For convenience of description, the above steps S12 and S13 will be described in combination.
In the embodiment of the application, firstly, a lexical analyzer is used for dividing the character string corresponding to the target complex operator into morphemes (token) so as to provide a basis for subsequent grammar analysis. Secondly, a syntax analyzer is used for converting morphemes into a tree structure body formed by combining a plurality of basic operators. Thus, the analysis of a complex operator from the input formula character string to morphemes to a tree structure body can be automatically completed. The tree structure completes the parsing of complex operators into individual base operators.
In a specific embodiment, the tree structure is automatically generated by a Flex & Bison (F & B) tool, and the automatic analysis from the complex operator to the basic operator is completed. It will be understood by those skilled in the art that the Flex & Bison (F & B) tool is merely illustrative, and is not limited to the automatic parsing process of the operator, and in the following embodiments, the Flex & Bison is taken as an example, and will not be described in detail.
Flex & Bison is a pair of automatic code generation tools based on the C/C++ language. The Flex is used as a lexical analyzer, and can divide an input source code character string into morphemes one by one so as to provide a basis for subsequent grammar analysis; bison acts as a parser that can perform necessary operations on the morphemes generated by the lexical parser based on grammar rules and production formulas. Flex and Bison provide powerful functions and flexible configuration options that can help developers build parsers and converters more easily and automatically generate executable code by using Flex and Bison tools.
It should be noted that Flex & Bison has perfect error detection and processing capability, so in the process of resolving the complex operator of the target, it further includes: and detecting the mathematical expression of the operator by using the lexical analyzer and/or the grammar analyzer, and prompting the mathematical expression errors and anomalies of the operator found in the detection process. In this way, the developer can be helped to detect and process errors and abnormal conditions in the operator expression, and the robustness and reliability of codes are improved.
Therefore, in the embodiment of the application, efficient, accurate and reliable analysis of the complex operator can be realized by using Flex and Bison tools, and further, the function of an automatic generation analyzer for analyzing the complex operator is realized. Compared with a method for manually writing a parser, the method has the advantages of greatly improving development efficiency, reducing errors and providing better maintainability.
An implementation flow diagram of an automatically generated parser based on lexical and grammatical analysis implementations is shown in fig. 3. When complex operator analysis is realized by using Flex and Bison tools, the Flex is used as a lexical analyzer to predefine a first analysis rule, and then character strings corresponding to the operators are automatically generated and analyzed into morphemes according to the first analysis rule; and the Bison serves as a grammar analyzer to predefine a second analysis rule, and then the generation formula for completing the generation according to the morpheme is automatically generated according to the second analysis rule, so that the morpheme can be converted into a tree structure body formed by combining a plurality of basic operators. It can be understood that in the subsequent implementation process, the implemented automatic generation parser can be directly called by the main program to complete the automatic parsing of the complex operator, and only mathematical expressions of the complex operator need to be input. For example, here the Flex & Bison generated auto-generated parser is called via getParse () interface, parsing complex operators into tree structures.
Step S14: and analyzing the target complex operator into a corresponding basic operator according to the tree structure body so as to obtain a calculation result corresponding to the target complex operator based on the basic operator obtained after analysis.
In the embodiment of the application, the tree structure body generated by the lexical analyzer and the grammar analyzer sequentially completes the automatic analysis from the target complex operator to the basic operator, thereby completing the analysis of different complex operators in AI models of different chips into a common basic operator which can be used universally. Because the complexity of the basic operator is lower and the development difficulty is also lower, the basic operator obtained after analysis is used for carrying out operation on the target complex operator to obtain a corresponding calculation result, and the development efficiency can be effectively improved.
Specifically, the calculation process of the complex operator is automatically completed based on the basic operator, which comprises the following steps: calling each node in the tree structure body through a fifth preset interface to traverse the tree structure body to obtain a second operator code corresponding to the basic operator obtained after analysis; and calculating the target complex operator based on the second operator code to obtain a corresponding calculation result.
Illustratively, the Execute () interface is invoked, from the root node to the leaf node, according to a tree structure. Here the root node is all the inputs and the leaf nodes are the various base operators. And developing the basic operator after the call, and completing the calculation of the target complex operator according to the operator code of the basic operator.
It should be noted that, in the embodiment of the present application, an auxiliary file is further constructed to include additional structures and rules required in the entire parsing process. Such as regular expression definitions, data structure definitions, auxiliary function declarations, and the like.
Specifically, a regular expression definition, a data structure definition and an auxiliary function statement are obtained; the regular expression definition is used for generating a preset regular matching rule for decomposing the character strings corresponding to the target complex operator; the data structure defines a structure body for generating and storing the basic operator; the auxiliary function declaration is used for defining functions except functions declared by the lexical analyzer and the grammar analyzer; and constructing an auxiliary file based on the regular expression definition, the data structure definition and the auxiliary function statement so as to execute the operator analysis method based on the lexical and grammatical analysis based on the auxiliary file.
In a specific embodiment, the technical scheme of the application can be applied to the field of automatic driving. Namely: acquiring complex operator requirements to be realized from an artificial intelligent model and/or a deep learning algorithm framework for providing automatic driving service, and determining a target complex operator to be analyzed according to the complex operator requirements in an automatic driving scene; the complex operator requirement is a requirement of analyzing the complex operator into a basic operator, wherein the basic operator is an operator used for single operation, and the complex operator is an operator obtained by combining at least two basic operators; acquiring a first analysis rule predefined by a lexical analyzer, and analyzing a character string corresponding to the target complex operator in an automatic driving scene into morphemes according to the first analysis rule; acquiring a second analysis rule predefined by a grammar analyzer, and converting morphemes corresponding to the target complex operator in the automatic driving scene into corresponding tree-shaped structures according to the second analysis rule; and analyzing the target complex operator in the automatic driving scene into a corresponding basic operator according to the tree structure body so as to obtain a calculation result corresponding to the target complex operator in the automatic driving scene based on the basic operator obtained after analysis. It can be understood that, besides the application of the technical solution of the present application in the automatic driving field, other scenes where complex operator development needs exist, such as face image recognition, voice recognition, etc., which are not illustrated here.
The application provides an operator analysis method based on lexical and grammatical analysis, which comprises the following steps: acquiring complex operator requirements to be realized from an artificial intelligent model and/or a deep learning algorithm framework, and determining a target complex operator to be analyzed according to the complex operator requirements; the complex operator requirement is a requirement of analyzing the complex operator into a basic operator, wherein the basic operator is an operator used for single operation, and the complex operator is an operator obtained by combining at least two basic operators; acquiring a first analysis rule predefined by a lexical analyzer, and analyzing a character string corresponding to the target complex operator into morphemes according to the first analysis rule; acquiring a second parsing rule predefined by a grammar parser, and converting morphemes corresponding to the target complex operator into corresponding tree-shaped structures according to the second parsing rule; and analyzing the target complex operator into a corresponding basic operator according to the tree structure body so as to obtain a calculation result corresponding to the target complex operator based on the basic operator obtained after analysis.
The beneficial technical effects of the application are as follows: for the development requirements of multiple complex operators of multiple AI models and deep learning algorithm frameworks, automatic parsing of the target complex operator into the base operator is achieved by using a lexical analyzer and a grammar analyzer. Meanwhile, according to the analysis rule of the complex operator, the input of multiple types of complex operators can be processed and analyzed into corresponding basic operators, and the method has good usability and expandability. When the operator analysis code is automatically generated based on a tree structure body formed by a plurality of basic operators for development, not only the workload of manual writing and maintenance can be reduced, but also errors can be reduced, better maintainability can be provided, and the code can adapt to the continuously updated AI chip and multi-chip environment. Therefore, the development efficiency is effectively improved, and the development cost is reduced.
The second embodiment of the operator analysis method based on lexical and grammatical analysis provided by the invention is realized based on the first embodiment, and is expanded to a certain extent based on the first embodiment. Referring to fig. 4, the method includes:
Step S21: and acquiring complex operator requirements to be realized from the artificial intelligent model and/or the deep learning algorithm framework, and determining a target complex operator to be analyzed according to the complex operator requirements.
For more specific processing in step S21, reference may be made to the corresponding content disclosed in the foregoing embodiment, and no further description is given here.
Step S22: analyzing and recording the target complex operator as a corresponding first mathematical expression so as to determine a character string corresponding to the target complex operator according to the first mathematical expression; constructing a data management file with a preset data format, and managing the character strings corresponding to the target complex operator through the data management file.
In the embodiment of the application, after the complex operator requirements to be realized are extracted from the AI model and/or the deep learning algorithm frame, the target complex operator to be analyzed is analyzed and recorded as the corresponding mathematical expression, and the character string corresponding to the target complex operator can be determined according to the mathematical expression.
Furthermore, the mathematical expression of the target complex operator and the corresponding character string are managed through a data management file. For example, YAML (YAML Ain't Markup Language, another markup language, a format that is highly readable to express data serialization), JSON (Java Script Object Notation, JS object profile, a lightweight data interchange format, JS, collectively referred to as Java Script, a programming language), XML (Extensible Markup Language ), INI (Initialization File, initialization file) tools, and the like. In a specific embodiment, taking YAML format management as an example, some of the code in the YAML file of the present application is exemplified as follows:
FundamentalFuncs:
- func: Add
cpu_impl: "v[0] + v[1]"
output_info: GetBinaryOpsOutInfo
- func: Exp
cpu_impl: "std::exp(v[0])"
output_info: CloneOutInfoFromInput0
- func: Log
cpu_impl: "std::log(v[0])"
output_info: CloneOutInfoFromInput0
CompoundFuncs:
- func: out = Acosh(x)
expressions:
- out: Log(x + Sqrt(x ** ScalarToTensor(2) - 1))
- func: out = Asinh(x)
expressions:
- out: Log(x + Sqrt(x ** ScalarToTensor(2) + 1))
- func: out = Atanh(x)
expressions:
- out: Log((1+x)/(1-x))/2
# divide_grad: dx = dout/y = 1/y * dout, dy = -output * (dout/y) = -output/y * dout
- func: dx, dy = Divide_Grad(x, y, output, dout, axis)
expressions:
- ti: Initial(x, y, output, dout, axis)
- t0: dout / y
- t2: -output / y * dout
- t3: GetReduceAxes(axis, dout, out_dx, x, y)
- t4: GetReduceAxes(axis, dout, out_dy, x, y)
- t5: ReduceAdd(t0, t3)
- t6: ReduceAdd(t2, t4)
- t7: IsShapeEqual(out_dx, dout)
- t8: IsShapeEqual(out_dy, dout)
- out_dx: if(t7, t0, t5)
- out_dy: if(t8, t2, t6);
It should be noted that the data management file is not only capable of managing different common basic operators, such as basic operators defined in yaml, such as Add, exp, log; some basic complex operators which are realized can be managed, such as Acosh, asinh, atanh and the like, and can be resolved into the complex operators of the basic operators. Meanwhile, the data management file can also manage operators in the data management file according to the development requirement of new operators accessed each time, and the operators only need to be added in the yaml file. In this way, the data management file can be utilized to manage through the development of the common public operator, so that the development efficiency is effectively improved.
Specifically, for an artificial intelligent model and/or a deep learning algorithm frame which are newly accessed currently, determining a corresponding new operator development requirement according to the artificial intelligent model and/or the deep learning algorithm frame which are newly accessed; and determining a target operator which does not exist in the data management file according to the new operator development requirement and the complex operator requirement, and adding the target operator to the data management file.
Step S23: determining a character string corresponding to the target complex operator from the data management file; and acquiring a first analysis rule predefined by the lexical analyzer, and analyzing the character string into morphemes according to the first analysis rule.
In the embodiment of the application, the mathematical expression of the operator and the corresponding character string are managed through the data management file, so that the character string corresponding to the target complex operator can be determined from the data management file in the process of analyzing the target complex operator. The character string may be a character string of a plurality of basic operators constituting the target complex operator, or may be a character string corresponding to the target complex operator itself. It will be appreciated that the mathematical expression of the target complex operator may also be managed by the data management file if it was previously parsed for the target complex operator. Then, when the target complex operator is the operator which is analyzed originally, the character string determined at this time is the character string of the target complex operator itself.
It should be noted that when performing the backend operator development task, management and preprocessing of each operator in the data management file is required. Specifically, a first preset interface is called to obtain a second mathematical expression of the basic operator in the data management file; and calling a second preset interface to judge whether a missing basic operator exists in the data management file and/or whether each basic operator is analyzed or not according to the first mathematical expression and the second mathematical expression.
Illustratively, the CallOp () interface is first invoked to obtain the mathematical expressions of all the base operators in the yaml file. Then, through IsSupport () interface, the judgment of the supporting condition of the operators is completed, such as whether the analysis of each basic operator is realized, which basic operators are absent, etc.
It should be noted that, when the mathematical expression of the basic operator is managed through the data management file, the normalized regularization is also performed on the name string and the data input by the basic operator. At this time, the name string and the data of the basic operator are normalized and regularized by calling getRegex () interface.
Step S24: and acquiring a second parsing rule predefined by the grammar analyzer, and converting morphemes corresponding to the target complex operator into corresponding tree structures according to the second parsing rule.
It should be noted that when new operator development requirements exist, the lexical analyzer and the grammar analyzer also add new parsing rules in the parsing rules corresponding to the new operator development requirements, so as to update the parsing rules, thereby adapting to the complex operator development requirements of multiple AI models and deep learning algorithm frameworks. For more specific processing in step S24, reference may be made to the corresponding content disclosed in the foregoing embodiment, and no further description is given here.
Step S25: storing the tree structure body according to the data structure definition in the auxiliary file, and judging whether a lacking basic operator exists in the tree structure body; if the missing base operator exists in the tree structure, the missing base operator is directly added to the data management file.
Based on the foregoing embodiments, the present application constructs an auxiliary file containing additional structures and rules required in the entire parsing flow. Therefore, in the embodiment of the application, after the target complex operator is analyzed to obtain the tree structure body composed of a plurality of basic operators, the tree structure body is stored according to the data structure definition in the auxiliary file. Specifically, a node structure is defined in the auxiliary file, and partial codes are exemplified as follows:
struct Node {
std::string node_label_;
std::string operator_str_;
std::vector<Node*>branches_;
std::vector<Tensor*>tensor_values_;
};
The structure body is in a tree form and is used for storing basic operators analyzed by complex operators. If the lack of basic operators is found, the basic operators are directly added in the yaml file.
Step S26: and analyzing the target complex operator into a corresponding basic operator according to the tree structure body so as to obtain a calculation result corresponding to the target complex operator based on the basic operator obtained after analysis.
For more specific processing in step S26, reference may be made to the corresponding content disclosed in the foregoing embodiment, and no further description is given here.
It can be seen that, according to this embodiment, the mathematical expressions of different operators and the corresponding character strings are managed by one data management file. Therefore, when the automatic analysis process of the operator is carried out, the generated codes can adapt to the environments of the continuously updated AI chips and the multiple chips. For the access of the AI model corresponding to the new chip, namely the new complex operator demand, the operator demand can be directly added in the operator management part, and then the analysis rule is correspondingly added through Flex and Bison, so that the method has good expandability.
Based on the above embodiment, in order to enable development of the basic operator at the same time, in a possible implementation manner, the third embodiment performs development work with respect to the operator development requirement that is currently implemented only by the basic operator. Specifically, the method can further comprise the following steps:
Step one: determining a target basic operator corresponding to the operator development requirement, and preprocessing the target basic operator according to the data management file to obtain a processed character string;
step two: constructing a fourth preset interface for inputting operator codes of the target basic operator, and acquiring a first operator code of the target basic operator through the fourth preset interface;
step three: and calculating the target basic operator based on the first operator code to obtain a corresponding calculation result.
In the embodiment of the application, if the operator development requirement does not relate to the analysis process of the complex operator, namely, the current operator development requirement is the development requirement which can be realized only through the basic operator. And determining a target basic operator corresponding to the current operator development requirement. And then preprocessing the target basic operator according to the data management file to obtain a processed character string. For example, currently if a+b is to be implemented, it is treated as aand b after preprocessing.
It will be appreciated that development difficulties are lower due to the lower complexity of the underlying operators. Therefore, in the embodiment of the application, a developer is required to manually realize the development of operators for all basic operators. Manual input of the base operator code is achieved by constructing an interface for inputting the code of the base operator. Further, aiming at the development of the basic operator, the target basic operator is calculated based on the first operator code to obtain a corresponding calculation result.
Therefore, in the embodiment, a flexible expansion interface is provided at the same time, so that a developer is allowed to manually realize the development of different basic operators, further realize the expansion and optimization according to the needs based on the basic operators, and meet the access of an AI model of a new chip and the realization of new needs.
Based on the above embodiment, the fourth embodiment will specifically explain S12 in the above embodiment. Wherein, in order to enable the lexical analyzer to automatically generate and realize parsing from the character string into morphemes, the process of parsing the character string corresponding to the target complex operator into morphemes according to the first parsing rule may include the following steps:
step one: decomposing the character strings corresponding to the target complex operators by using a preset regular matching rule to obtain a plurality of decomposed characters;
Step two: matching the decomposed character with the recognition character to analyze the character string corresponding to the target complex operator into morphemes; wherein the identification character is a character with an output mark set.
The specific process of Flex for generating a lexical analyzer is described in the embodiments of the present application. The main function of the lexical analyzer is to read the source code (or any text file), decompose it into a series of morphemes (tokens), and complete the action analysis according to the rules corresponding to the morphemes. Specifically, flex is responsible for translating regular expressions into functions yylex (), which can be considered a finite state automaton, of the C code format.
The standard format of Flex is largely divided into four parts, separated by "% {", "% }", and "%". The specific implementation pseudo code is as follows; wherein, input: mathematical expressions (string forms) of complex operators; and (3) outputting: a morpheme group.
%{
The// declarations (Declarations) -contained in% { and% }, the C code, typically where global variables and functions are declared, would be copied as it is into the generated. Cpp file.
#include<string.h>
# Include "Parser.h"// various header files
Extern int yylex ();// interface declaration
%}
Definition-some additional optional Definitions.
% Option outfile = "lexer.cpp" header-file= "lexer h"// control generates names of the. Cpp file and the. H header file
%%
The/(Rules) -action resolution is done in this section. One row is a rule, each rule is composed of a match pattern (before, regular expression) and an event action (after, C code), and when a pattern is matched, the corresponding action is performed.
In the embodiment of the invention, a mathematical formula corresponding to a complex operator is required to be used as a character string to be input, the character string is decomposed through a self-fitting regular matching rule, and the following operations are realized:
[ \t\n] ;
When symbol characters are identified, yytext [0] is output, which means that the character is output without transformation;
when "/recognizes"/the method outputs a morpheme POWER
pi { return PI; }
out { yylval.strval = strdup(yytext); return RESULT; }
Out_ [ a-zA-Z0-9] [ a-zA-Z0-9_ ] { yylval. Strval = strdup (yytext); return RESULT;}// when "out" or "out_" plus other characters are recognized, yylval strval = strdup (yytext) means that the string (which is used in Bison) is recorded and a morpheme RESULT is output;
[ a-zA-z_ ] [ a-zA-Z0-9_ ] [ yylval. Strval= strdup (yytext); return IDENTIFIER }// recognizes that the variable name ([ a-zA-Z0-9_ ]) indicates that the first character must be english letter (uppercase or lowercase) or underline_, the following character may be english letter (uppercase or lowercase), digits 0-9 or underline_), records the length of the string, and outputs a morpheme IDENTIFIER;
- [0-9] + (/ 0-9] +) { (yyval. Strval= strdup (yytext); return NUMBER;// identify digital group (- [0-9] + (/ 0-9] +);
{ printf("Invalid character: %s\n", yytext); }
%%
The/(user subroutine (User subroutines) -C code, will be copied as is into the generated cpp file, generally defining the functions stated in Declarations herein. This part may be omitted.
It can be seen that in the above pseudo code, corresponding output marks are set for different character forms, respectively. For example, when ". Times." is recognized, an output flag POWER corresponding to one morpheme is output, a variable name ([ a-zA-z_ ] [ a-zA-Z0-9_ ] (the first character must be english letters (uppercase or lowercase) or underlined, the subsequent characters may be english letters (uppercase or lowercase), numerals 0-9 or underlined) is recognized, an output flag idenfier corresponding to one morpheme is output, and the like.
The following is exemplified by Flex implementations:
Taking a "simple" complex operator atanh as an example, this complex operator can be mathematically decomposed as follows: out=atanh (x) =log ((1+x)/(1-x))/2
I.e., atanh may be implemented by "log, +, -,/". Firstly, carrying out normalization and regularization on the expression, and changing the expression into out:log ((1+x)/(1-x))/2; after the Flex defined above, the string of the expression is automatically parsed into an ordered morpheme group of [ "out", "" log "," ("," "1", "+", "" x ","/""1"," - "," "x", ")", "/" "2" ].
Based on the above embodiment, the fifth embodiment will specifically explain S13 in the above embodiment. In order to enable the parser to automatically generate a tree structure body formed by combining a plurality of basic operators according to the morpheme conversion, the process of converting the morpheme corresponding to the target complex operator into a corresponding tree structure body according to the second parsing rule may include the following steps:
and sequentially determining node structures corresponding to the morphemes based on a preset analysis sequence and by utilizing a generation type, and generating the tree structure based on the node structures.
After morphemes are obtained by Flex, they need to be parsed by Bison. The specific process of using the Bison to generate the parser is described in the embodiments of the present application. The standard format of Bison is also divided into four parts, also separated by "% {", "% }", and%. The specific implementation pseudo code of the Bison is shown below; wherein, input: a morpheme group; and (3) outputting: and a node structure body for storing a basic operator group formed by analyzing the complex operator.
%{
The// declaration (Declarations) -like Flex-is copied as it is into the generated. Cpp file. Some function interfaces need to be defined in this section, and this section of functions is used in the third section of the production formula.
# Include < string.h >// various header files
#include<iostream>
#include "/include/node.h"
Extern int yylex ();// interface declaration
Std: stack < std:: vector < char > > paramser_stack:// initialization of variables
std::map<std::string, Node*>tree_map_;
std::vector<char*>allocated_ptr;
void leafNodeCreation(char* chartemp, std::string nodelabel) {
auto itl = tree_map_.find(std::string(chartemp));
if (itl == tree_map_.end()) {
tree_map_[std::string(chartemp)]=new Node(std::string(nodelabel));
// serial number update
if (std::regex_match(nodelabel, input_regex)){
inputcount += 1;
} else if (std::regex_match(nodelabel,:output_regex)){
outputcount += 1;
} else if (std::regex_match(nodelabel, constant_regex_v2)) {
}
}
"Functions// some of the functions used in the production are listed here as leafNodeCreation { } used to create a leaf node
%}
Definition (definition) -definition of a Bison proprietary variable, typically comprising% union,%start,%token,%type,%left,
% Right,% nonassoc, and the like
%token<strval>IDENTIFIER
%token<strval>NUMBER
%token<strval>PI
%token<strval>POWER
% Token < strval > RESULT// indicates that IDENTIFIER, etc., is a morpheme, is a string value
% Type < strval > expr// declares non-terminal expr, also a string value
% Start expr// specifies the start symbol and the parser will parse the input starting at expr
%%
The// production (Productions) -the grammar production written by the user, i.e., tells the parser how the individual morphemes need to be processed.
expr:
Expr '+' expr// processing a combination of morphemes of one of two expr '+' to create a node structure, structure operator str is "Add", and two brands are two expr respectively
{
size_t maxLength = getLength();
char* tempIndex = (char*)malloc(maxLength);
getTempIndex(tempIndex, maxLength);
char* chartemp1 = $1;
char* chartemp3 = $3;
// subnode creation check
leafNodeCreation(chartemp1, std::string("parsing add, should not reach here"));
leafNodeCreation(chartemp3, std::string("parsing add, should not reach here"));
// internode creation
std::vector<Node*>internodetemp;
internodetemp.emplace_back(tree_map_[std::string($1)]);
internodetemp.emplace_back(tree_map_[std::string($3)]);
interNodeCreation(tempIndex, "Add", internodetemp);
allocated_ptr.emplace_back(tempIndex);
$$ = tempIndex;
count += 1;
}
The i IDENTIFIER// process expr is the case for an IDENTIFIER, e.g., process x, creating a leaf node.
{
char* chartemp1 = $1;
std::string nodelabel = std::string("node##input")+std::to_string(inputcount);
leafNodeCreation(chartemp1, nodelabel);
allocated_ptr.emplace_back($1);
$$ = $1;
}
The NUMBER// process expr is the case for a NUMBER, e.g., process x, creating a leaf node.
{
char* chartemp1 = $1;
std::string nodelabel = std::string("node##constant_")+std::string($1);
leafNodeCreation(chartemp1, nodelabel);
allocated_ptr.emplace_back($1);
$$ = $1;
}
%%
The/(user subroutine (User subroutines) -like Flex, is copied as it is into the generated cpp file, which may be omitted
void yyerror(const char* s) {
throw std::runtime_error(s);
Exception handling is performed.
It can be seen from the above pseudo code that the automatic generation of the realization-based morpheme completion generation formula by the parser. For example, process expr is an IDENTIFIER case, such as process x, creating a leaf node; processing a combination of morphemes of one "+" in two expr creates a node structure with structure operator str "Add" and two branches expr respectively.
The following is exemplified by the Bison implementation:
A portion of the resulting code is listed in the pseudo code third section. First, a node structure is defined in the auxiliary document, and the partial code of the structure may refer to the node structure code example given in the foregoing embodiment.
Taking out=log ((1+x)/(1-x))/2 as an example, the operation will be briefly analyzed.
First, after Flex analysis, out:log ((1+x)/(1-x))/2 has been converted into an ordered morphological group of [ "out", ":," "log", "(", ""1"," + "," x ","/""1"," - "," x ",") ","/""2 "]. According to the predefined parsing order, we first locate the morpheme "1" satisfying the generating equation expr, parse this NUMBER into a expr according to the code, and generate a node structure, recorded as: { "1": leafnode, label_ node # # constant_1, no any branches_ }; then locating to the morpheme "x" satisfying the generating equation expr, resolving this idetifier to one expr and generating a node structure, recorded as: { "x": leafnode, label_ node # # input0, no any branches_ }; then resolving it to 1+x satisfying expr: expr '+' expr, then generating 1+x into a node structure :{"node##tmp1000Atanh": label_: node##tmp1000, str_: Add, branches_ are: { node##constant_1 node##input0 }}.
By analogy, according to the generation formula defined in Bison, the final result will be:
{"1": Leafnode, label_: node##constant_1, no any branches_.}
{"2": Leafnode, label_: node##constant_2, no any branches_.}
{"node##out0Atanh": label_: node##out0, str_: Divide, branches_ are: { node##tmp1003 node##constant_2 }}.
{"node##tmp1000Atanh": label_: node##tmp1000, str_: Add, branches_ are: { node##constant_1 node##input0 }}.
{"node##tmp1001Atanh": label_: node##tmp1001, str_: Subtract, branches_ are: {node##constant_1 node##input0 }}.
{"node##tmp1002Atanh": label_: node##tmp1002, str_: Divide, branches_ are: { node##tmp1000 node##tmp1001 }}.
{"node##tmp1003Atanh": label_: node##tmp1003, str_: log, branches_ are: { node##tmp1002 }}.
{"x": Leafnode, label_: node##input0, no any branches_.}。
FIG. 5 shows the tree-like structure of atanh that is a node structure that can be used for subsequent code processing after Flex & Bison analysis. Firstly, normalized regularization is carried out on the expression of the input complex operator atanh to obtain: out: log ((1+x)/(1-x))/2; further realizing a predefined automatic generation parser through Flex & Bison to obtain a tree structure body of the complex operator; the root node, the internal node and the leaf node can be determined by the tree structure, and each node corresponds to the content of the related node structure defined in the pseudo code. It can be seen from fig. 5 that, through the predefined operation in Flex & Bison, the parsing of a complex operator from the input formula string to the morpheme group and then to a tree structure can be automatically completed. The tree structure completes the parsing of complex operators into individual base operators.
The implementation process of the operator parsing method based on the lexical and grammatical analysis is described in the following with a specific embodiment, and an automatic parsing system is implemented by using the operator parsing method based on the lexical and grammatical analysis. Referring to fig. 6, a system architecture diagram is shown for exemplary purposes. The system operation flow is specifically as follows:
(1) And (3) demand extraction: acquiring complex operator requirements to be realized from an artificial intelligent model and/or a deep learning algorithm framework;
(2) And (3) demand management: the complex operator demand is preprocessed and managed by the data management file. Specifically, this step is divided into two sub-stages, basic operator management and complex operator resolution, respectively. Various basic operators are managed by utilizing a data management file, and simultaneously, the basification of the complex operators can be automatically completed by calling the Flex & Bison tool disclosed in the previous embodiment when the target complex operators are preprocessed, and an automatic generation parser based on lexical and grammatical parsing is obtained;
It should be noted that in the preprocessing step, the two sub-phases normalize and regularize the character string by calling getRegex () interface.
(3) Operator development: this step is also divided into two sub-phases, respectively a basic operator development and a complex operator basification implementation. Judging whether the operator is a complex operator for the operator after normalization and regularization; if not, manually developing the basic operators by a developer after preprocessing the basic operators for all the basic operators; if so, for the complex operator, the analyzer automatically completes the foundational of the complex operator, and analyzes the complex operator into a tree structure body formed by basic operators. Specifically, by calling the Execute () interface, calls are made from the root node to the leaf node according to the node tree structure, and the calculation of the complex operator is automatically completed based on the basic operator.
(4) And (3) system call: after the flow of the steps is finished, the automatic analysis of the complex operator can be finished simply by inputting the name character string and the data of the complex operator. For example, a preset interface computer ("atanh", x) may be called to complete the operator calculation, so as to obtain a calculation result.
Therefore, the operator analysis method based on the lexical and grammatical analysis can complete a complete basic operator generation system, can realize the butt joint of the AI model and the bottom basic operator and complete the required task; the system can process various types of input and resolve the input into corresponding basic operators in the AI scene. The system realizes a complete system architecture based on C++, is based on a lexical analyzer and a grammar analyzer, is matched with other necessary modules and components, completely realizes the development, management and maintenance of complex operators in a deep learning algorithm, and has good usability and expandability.
Correspondingly, the embodiment of the application also discloses an operator analysis device based on lexical and grammatical analysis, which is shown in fig. 7 and comprises:
The requirement extraction module 11 is configured to obtain a complex operator requirement to be implemented from an artificial intelligent model and/or a deep learning algorithm framework, and determine a target complex operator to be resolved according to the complex operator requirement; the complex operator requirement is a requirement of analyzing the complex operator into a basic operator, wherein the basic operator is an operator used for single operation, and the complex operator is an operator obtained by combining a plurality of basic operators;
The first parsing module 12 is configured to obtain a first parsing rule predefined by a lexical analyzer, and parse a character string corresponding to the target complex operator into morphemes according to the first parsing rule;
The second parsing module 13 is configured to obtain a second parsing rule predefined by the parser, and convert morphemes corresponding to the target complex operator into corresponding tree structures according to the second parsing rule;
The operator parsing module 14 is configured to parse the target complex operator into a corresponding basic operator according to the tree structure, so as to perform an operation based on the basic operator obtained after parsing to obtain a calculation result corresponding to the target complex operator.
The more specific working process of each module may refer to the corresponding content disclosed in the foregoing embodiment, and will not be described herein.
It can be seen that by the above scheme of the present embodiment, it includes: acquiring complex operator requirements to be realized from an artificial intelligent model and/or a deep learning algorithm framework, and determining a target complex operator to be analyzed according to the complex operator requirements; the complex operator requirement is a requirement of analyzing the complex operator into a basic operator, wherein the basic operator is an operator used for single operation, and the complex operator is an operator obtained by combining at least two basic operators; acquiring a first analysis rule predefined by a lexical analyzer, and analyzing a character string corresponding to the target complex operator into morphemes according to the first analysis rule; acquiring a second parsing rule predefined by a grammar parser, and converting morphemes corresponding to the target complex operator into corresponding tree-shaped structures according to the second parsing rule; and analyzing the target complex operator into a corresponding basic operator according to the tree structure body so as to obtain a calculation result corresponding to the target complex operator based on the basic operator obtained after analysis.
The beneficial technical effects of the application are as follows: for the development requirements of multiple complex operators of multiple AI models and deep learning algorithm frameworks, automatic parsing of the target complex operator into the base operator is achieved by using a lexical analyzer and a grammar analyzer. Meanwhile, according to the analysis rule of the complex operator, the input of multiple types of complex operators can be processed and analyzed into corresponding basic operators, and the method has good usability and expandability. When the operator analysis code is automatically generated based on a tree structure body formed by a plurality of basic operators for development, not only the workload of manual writing and maintenance can be reduced, but also errors can be reduced, better maintainability can be provided, and the code can adapt to the continuously updated AI chip and multi-chip environment. Therefore, the development efficiency is effectively improved, and the development cost is reduced.
In a specific embodiment, the operator parsing device based on lexical and grammatical analysis further includes:
the character string acquisition module is used for analyzing and recording the target complex operator into a corresponding first mathematical expression so as to determine a character string corresponding to the target complex operator according to the first mathematical expression;
The management file construction module is used for constructing a data management file with a preset data format and managing the character strings corresponding to the target complex operator through the data management file;
Correspondingly, the first parsing module 12 is specifically configured to:
Determining a character string corresponding to the target complex operator from the data management file; and acquiring a first analysis rule predefined by the lexical analyzer, and analyzing the character string into morphemes according to the first analysis rule.
In a specific embodiment, the operator parsing device based on lexical and grammatical analysis further includes:
The preprocessing module is used for calling a first preset interface to acquire a second mathematical expression of the basic operator in the data management file; and calling a second preset interface to judge whether a missing basic operator exists in the data management file and/or whether each basic operator is analyzed or not according to the first mathematical expression and the second mathematical expression.
In a specific embodiment, the operator parsing device based on lexical and grammatical analysis further includes:
The new development requirement acquisition module is used for determining corresponding new operator development requirements according to the new access artificial intelligent model and/or the deep learning algorithm framework if the new access artificial intelligent model and/or the deep learning algorithm framework exists currently;
and an operator adding module, configured to determine a target operator that does not exist in the data management file according to the new operator development requirement and the complex operator requirement, and add the target operator to the data management file.
In a specific embodiment, the operator parsing device based on lexical and grammatical analysis further includes:
The definition data acquisition module is used for acquiring regular expression definitions, data structure definitions and auxiliary function declarations; the regular expression definition is used for generating a preset regular matching rule for decomposing the character strings corresponding to the target complex operator; the data structure defines a structure body for generating and storing the basic operator; the auxiliary function declaration is used for defining functions except functions declared by the lexical analyzer and the grammar analyzer;
and the auxiliary file construction module is used for constructing an auxiliary file based on the regular expression definition, the data structure definition and the auxiliary function statement so as to execute the operator analysis method based on the lexical and grammatical analysis based on the auxiliary file.
In a specific embodiment, the operator parsing device based on lexical and grammatical analysis further includes:
The operator checking module is used for storing the tree-shaped structure body according to the data structure definition in the auxiliary file and judging whether a lacking basic operator exists in the tree-shaped structure body or not; if the missing base operator exists in the tree structure, the missing base operator is directly added to the data management file.
In a specific embodiment, the operator parsing device based on lexical and grammatical analysis further includes:
And the normative regular module is used for calling a third preset interface and carrying out normative regular on the name character string and the data which are correspondingly input by the target complex operator so as to obtain corresponding normative expression characters.
In a specific embodiment, the first parsing module 12 is specifically configured to:
Decomposing the character strings corresponding to the target complex operators by using a preset regular matching rule to obtain a plurality of decomposed characters; matching the decomposed character with the recognition character to analyze the character string corresponding to the target complex operator into morphemes; wherein the identification character is a character with an output mark set.
In a specific embodiment, the second parsing module 13 is specifically configured to:
and sequentially determining node structures corresponding to the morphemes based on a preset analysis sequence and by utilizing a generation type, and generating the tree structure based on the node structures.
In a specific embodiment, the operator parsing device based on lexical and grammatical analysis further includes:
And the anomaly detection module is used for detecting the mathematical expression of the operator by using the lexical analyzer and/or the grammar analyzer and prompting errors and anomalies of the mathematical expression of the operator found in the detection process.
In a specific embodiment, the operator parsing device based on lexical and grammatical analysis further includes:
A basic operator development module, configured to determine a target basic operator corresponding to an operator development requirement if there is an operator development requirement that is only implemented by the basic operator currently, and perform preprocessing on the target basic operator according to the data management file, so as to obtain a processed character string; constructing a fourth preset interface for inputting operator codes of the target basic operator, and acquiring a first operator code of the target basic operator through the fourth preset interface; and calculating the target basic operator based on the first operator code to obtain a corresponding calculation result.
In a specific embodiment, the operator parsing module 14 is specifically configured to:
Calling each node in the tree structure body through a fifth preset interface to traverse the tree structure body to obtain a second operator code corresponding to the basic operator obtained after analysis; and calculating the target complex operator based on the second operator code to obtain a corresponding calculation result.
Further, the embodiment of the present application further discloses an electronic device, and fig. 8 is a block diagram of an electronic device according to an exemplary embodiment, where the content of the diagram is not to be considered as any limitation on the scope of use of the present application.
Fig. 8 is a schematic structural diagram of an electronic device according to an embodiment of the present application. The electronic device may specifically include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input output interface 25, and a communication bus 26. The memory 22 is configured to store a computer program that is loaded and executed by the processor 21 to implement relevant steps in the lexical and grammatical analysis based operator parsing method disclosed in any of the foregoing embodiments. In addition, the electronic device in this embodiment may be a computer.
In this embodiment, the power supply 23 is configured to provide an operating voltage for each hardware device on the electronic device; the communication interface 24 can create a data transmission channel between the electronic device and the external device, and the communication protocol to be followed is any communication protocol applicable to the technical solution of the present application, which is not limited herein in detail; the input/output interface 25 is used for acquiring external input data or outputting external output data, and the specific interface type thereof may be selected according to the specific application requirement, which is not limited herein.
The memory 22 may be a carrier for storing resources, such as a read-only memory, a random access memory, a magnetic disk, or an optical disk, and the resources stored thereon may include an operating system 221, a computer program 222, data 223, and the like, and the data 223 may include various data. The storage means may be a temporary storage or a permanent storage.
The operating system 221 is used for managing and controlling various hardware devices on the electronic device and the computer program 222, which may be Windows Server, netware, unix, linux, etc. The computer program 222 may further include a computer program that can be used to perform other specific tasks in addition to the computer program that can be used to perform the lexical and grammatical analysis based operator parsing method performed by the electronic device as disclosed in any of the previous embodiments.
Further, embodiments of the present application also disclose a computer readable storage medium, where the computer readable storage medium includes random access Memory (Random Access Memory, RAM), memory, read-Only Memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, magnetic disk, or optical disk, or any other form of storage medium known in the art. The computer program, when executed by the processor, implements the operator parsing method based on lexical and grammatical analysis. For specific steps of the method, reference may be made to the corresponding contents disclosed in the foregoing embodiments, and no further description is given here.
In this specification, each embodiment is described in a progressive manner, and each embodiment is mainly described in a different point from other embodiments, so that the same or similar parts between the embodiments are referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant points refer to the description of the method section.
The steps of a lexical and grammatical analysis based operator parsing method or algorithm described in connection with the embodiments disclosed herein may be embodied directly in hardware, in a software module executed by a processor, or in a combination of the two. The software modules may be disposed in Random Access Memory (RAM), memory, read Only Memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
Finally, it is further noted that relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
The operator analysis method, device, equipment and medium based on lexical and grammatical analysis provided by the invention are described in detail, and specific examples are applied to the explanation of the principle and the implementation of the invention, and the explanation of the above examples is only used for helping to understand the method and the core idea of the invention; meanwhile, as those skilled in the art will have variations in the specific embodiments and application scope in accordance with the ideas of the present invention, the present description should not be construed as limiting the present invention in view of the above.

Claims (15)

1. An operator parsing method based on lexical and grammatical analysis, comprising:
Acquiring complex operator requirements to be realized from an artificial intelligent model and/or a deep learning algorithm framework, and determining a target complex operator to be analyzed according to the complex operator requirements; the complex operator requirement is a requirement of analyzing the complex operator into a basic operator, wherein the basic operator is an operator used for single operation, and the complex operator is an operator obtained by combining at least two basic operators;
Acquiring a first analysis rule predefined by a lexical analyzer, and analyzing a character string corresponding to the target complex operator into morphemes according to the first analysis rule; the character string corresponding to the target complex operator is a character string obtained by analyzing and recording the target complex operator as a corresponding first mathematical expression and determining according to the first mathematical expression;
Acquiring a second parsing rule predefined by a grammar parser, and converting morphemes corresponding to the target complex operator into corresponding tree-shaped structures according to the second parsing rule;
And analyzing the target complex operator into a corresponding basic operator according to the tree structure body so as to obtain a calculation result corresponding to the target complex operator based on the basic operator obtained after analysis.
2. The method for parsing an operator based on lexical and grammatical analysis according to claim 1, wherein after determining the target complex operator to be parsed according to the complex operator requirement, further comprising:
Analyzing and recording the target complex operator as a corresponding first mathematical expression so as to determine a character string corresponding to the target complex operator according to the first mathematical expression;
constructing a data management file with a preset data format, and managing a character string corresponding to the target complex operator through the data management file;
correspondingly, the obtaining the first parsing rule predefined by the lexical analyzer, and parsing the character string corresponding to the target complex operator into morphemes according to the first parsing rule includes:
determining a character string corresponding to the target complex operator from the data management file;
And acquiring a first analysis rule predefined by the lexical analyzer, and analyzing the character string into morphemes according to the first analysis rule.
3. The method for parsing an operator based on lexical and grammatical analysis according to claim 2, wherein before determining a string corresponding to the target complex operator from the data management file, further comprising:
calling a first preset interface to acquire a second mathematical expression of the basic operator in the data management file;
And calling a second preset interface to judge whether a missing basic operator exists in the data management file and/or whether each basic operator is analyzed or not according to the first mathematical expression and the second mathematical expression.
4. The lexical and grammatical analysis based operator parsing method of claim 2, further comprising:
If a new access artificial intelligent model and/or a deep learning algorithm frame exist currently, determining a corresponding new operator development requirement according to the new access artificial intelligent model and/or the deep learning algorithm frame;
And determining a target operator which does not exist in the data management file according to the new operator development requirement and the complex operator requirement, and adding the target operator to the data management file.
5. The lexical and grammatical analysis based operator parsing method of claim 2, further comprising:
Acquiring regular expression definitions, data structure definitions and auxiliary function declarations; the regular expression definition is used for generating a preset regular matching rule for decomposing the character strings corresponding to the target complex operator; the data structure defines a structure body for generating and storing the basic operator; the auxiliary function declaration is used for defining functions except functions declared by the lexical analyzer and the grammar analyzer;
and constructing an auxiliary file based on the regular expression definition, the data structure definition and the auxiliary function statement so as to execute the operator analysis method based on the lexical and grammatical analysis based on the auxiliary file.
6. The method for parsing operators based on lexical and grammatical analysis according to claim 5, further comprising, after said converting the morphemes corresponding to the target complex operators into corresponding tree structures according to the second parsing rule:
storing the tree structure body according to the data structure definition in the auxiliary file, and judging whether a lacking basic operator exists in the tree structure body;
if the missing base operator exists in the tree structure, the missing base operator is directly added to the data management file.
7. The method for analyzing operators based on lexical and grammatical analysis according to claim 1, wherein after obtaining the complex operator requirements to be realized from the artificial intelligence model and/or the deep learning algorithm framework and determining the target complex operator to be analyzed according to the complex operator requirements, further comprising:
And calling a third preset interface, and carrying out standardization regularization on the name character string and the data which are correspondingly input by the target complex operator so as to obtain corresponding standardization expression characters.
8. The method for parsing an operator based on lexical and grammatical analysis according to claim 1, wherein parsing the character string corresponding to the target complex operator into morphemes according to the first parsing rule includes:
Decomposing the character strings corresponding to the target complex operators by using a preset regular matching rule to obtain a plurality of decomposed characters;
Matching the decomposed character with the recognition character to analyze the character string corresponding to the target complex operator into morphemes; wherein the identification character is a character with an output mark set.
9. The method for parsing operators based on lexical and grammatical analysis according to claim 1, wherein said converting the morphemes corresponding to the target complex operators into corresponding tree structures according to the second parsing rule comprises:
and sequentially determining node structures corresponding to the morphemes based on a preset analysis sequence and by utilizing a generation type, and generating the tree structure based on the node structures.
10. The lexical and grammatical analysis based operator parsing method of claim 1, further comprising:
and detecting the mathematical expression of the operator by using the lexical analyzer and/or the grammar analyzer, and prompting the mathematical expression errors and anomalies of the operator found in the detection process.
11. The lexical and grammatical analysis based operator parsing method of any of claims 2 to 6, further comprising:
If operator development requirements only realized through the basic operators exist at present, determining a target basic operator corresponding to the operator development requirements, and preprocessing the target basic operator according to the data management file to obtain a processed character string;
constructing a fourth preset interface for inputting operator codes of the target basic operator, and acquiring a first operator code of the target basic operator through the fourth preset interface;
and calculating the target basic operator based on the first operator code to obtain a corresponding calculation result.
12. The method for parsing an operator based on lexical and grammatical analysis according to any one of claims 1 to 10, wherein parsing the target complex operator into a corresponding basic operator according to the tree structure so as to calculate based on the basic operator obtained after parsing to obtain a calculation result corresponding to the target complex operator includes:
Calling each node in the tree structure body through a fifth preset interface to traverse the tree structure body to obtain a second operator code corresponding to the basic operator obtained after analysis;
And calculating the target complex operator based on the second operator code to obtain a corresponding calculation result.
13. An operator parsing apparatus based on lexical and grammatical analysis, comprising:
The demand extraction module is used for acquiring complex operator demands to be realized from the artificial intelligent model and/or the deep learning algorithm framework, and determining target complex operators to be analyzed according to the complex operator demands; the complex operator requirement is a requirement of analyzing the complex operator into a basic operator, wherein the basic operator is an operator used for single operation, and the complex operator is an operator obtained by combining a plurality of basic operators;
The first analysis module is used for acquiring a first analysis rule predefined by the lexical analyzer and analyzing the character string corresponding to the target complex operator into morphemes according to the first analysis rule; the character string corresponding to the target complex operator is a character string obtained by analyzing and recording the target complex operator as a corresponding first mathematical expression and determining according to the first mathematical expression;
the second analysis module is used for acquiring a second analysis rule predefined by the grammar analyzer and converting morphemes corresponding to the target complex operator into corresponding tree-shaped structures according to the second analysis rule;
and the operator analysis module is used for analyzing the target complex operator into a corresponding basic operator according to the tree structure body so as to obtain a calculation result corresponding to the target complex operator based on the basic operator obtained after analysis.
14. An electronic device, comprising:
a memory for storing a computer program;
A processor for loading and executing the computer program to implement the steps of the lexical and grammatical analysis based operator parsing method of any of claims 1 to 12.
15. A computer-readable storage medium storing a computer program; wherein the computer program, when executed by a processor, implements the lexical and grammatical analysis based operator parsing method of any of claims 1 to 12.
CN202410380906.4A 2024-03-31 2024-03-31 Operator analysis method, device, equipment and medium based on lexical and grammatical analysis Active CN117971236B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202410380906.4A CN117971236B (en) 2024-03-31 2024-03-31 Operator analysis method, device, equipment and medium based on lexical and grammatical analysis

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202410380906.4A CN117971236B (en) 2024-03-31 2024-03-31 Operator analysis method, device, equipment and medium based on lexical and grammatical analysis

Publications (2)

Publication Number Publication Date
CN117971236A CN117971236A (en) 2024-05-03
CN117971236B true CN117971236B (en) 2024-06-18

Family

ID=90859844

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202410380906.4A Active CN117971236B (en) 2024-03-31 2024-03-31 Operator analysis method, device, equipment and medium based on lexical and grammatical analysis

Country Status (1)

Country Link
CN (1) CN117971236B (en)

Family Cites Families (15)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
DE102017103951A1 (en) * 2017-02-24 2018-08-30 Volume Graphics Gmbh Method and device for multiple edge detection
CN111666077B (en) * 2020-04-13 2022-02-25 北京百度网讯科技有限公司 Operator processing method and device, electronic equipment and storage medium
CN111309757B (en) * 2020-05-14 2020-09-01 深圳市赢时胜信息技术股份有限公司 SQL interpreter and optimization method of HBase
CN111880807A (en) * 2020-07-31 2020-11-03 Oppo广东移动通信有限公司 Deep learning compiling method, device, equipment and storage medium
CN112580805A (en) * 2020-12-25 2021-03-30 三星(中国)半导体有限公司 Method and device for quantizing neural network model
KR102298766B1 (en) * 2021-02-15 2021-09-07 주식회사 딥이티 Apparatus and method for converting deep learning model for target device
CN113420865A (en) * 2021-06-15 2021-09-21 之江实验室 Deep neural network reasoning acceleration method and system based on multi-operator fusion
CN114327405A (en) * 2021-12-28 2022-04-12 杭州海康威视数字技术股份有限公司 Data processing method, device, equipment and storage medium
KR20230120850A (en) * 2022-02-10 2023-08-17 한국전자통신연구원 Deep-learning compiler for supporting heterogeneous computing platform and method thereof
CN114218929B (en) * 2022-02-22 2022-05-17 之江实验室 Multi-platform operator intelligent development system and method based on meta-operator fusion
CN114841326B (en) * 2022-05-19 2024-01-12 北京百度网讯科技有限公司 Operator processing method, device, equipment and storage medium of deep learning framework
CN116185416A (en) * 2022-12-12 2023-05-30 深圳鲲云信息科技有限公司 Operator interface file generation method, device, equipment and storage medium
CN117270871A (en) * 2023-09-25 2023-12-22 亿咖通(湖北)技术有限公司 AI operator construction method, operation method, server and storage medium
CN117762404A (en) * 2023-11-29 2024-03-26 中国建设银行股份有限公司 Configurable operator processing method and device for data mining
CN117610555A (en) * 2023-12-05 2024-02-27 中国农业银行股份有限公司 Character string expression processing method, device, equipment and storage medium

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
人工智能算子接口标准化研究;黎子毅;李克森;李雨芮;范睿博;敖玉龙;杨超;;人工智能;20200610(03);全文 *
面向计算机视觉的领域特定语言;姜靖;郑启龙;;小型微型计算机***;20200315(03);全文 *

Also Published As

Publication number Publication date
CN117971236A (en) 2024-05-03

Similar Documents

Publication Publication Date Title
US8091071B2 (en) Method and system for template-based code generation
US9298427B2 (en) Creating inferred symbols from code usage
US20040158820A1 (en) System for generating an application framework and components
US9405518B2 (en) Leveraging legacy applications for use with modern applications
US20060200796A1 (en) Program development apparatus, method for developing a program, and a computer program product for executing an application for a program development apparatus
CN110673854A (en) SAS language compiling method, device, equipment and readable storage medium
CN109857389B (en) Model data generation method and device, computer equipment and storage medium
CN111736813B (en) JPA code generation method and device, terminal equipment and storage medium
CN108595334B (en) Method and device for calculating dynamic slices of Java program and readable storage medium
CN112667287A (en) Method, device and equipment for creating rule file and computer readable storage medium
CN109359055B (en) Data testing method and device
CN109325217B (en) File conversion method, system, device and computer readable storage medium
CN114356964A (en) Data blood margin construction method and device, storage medium and electronic equipment
Zhang et al. Automated extraction of grammar optimization rule configurations for metamodel-grammar co-evolution
Lano et al. Code Generation by Example.
CN111240681B (en) Conversion method and device for different programming languages
Kastens Attribute grammars in a compiler construction environment
CN117971236B (en) Operator analysis method, device, equipment and medium based on lexical and grammatical analysis
US8341607B2 (en) Condensing pattern matcher generation for intermediate language patterns
KR20090011974A (en) Method for extracting the target files of compilation
US11604774B2 (en) Method and apparatus of converting schema in deep learning framework, and computer storage medium
CN111831288B (en) Method and system for automatically generating Thrift IDL data structure and automatic transfer function
CN107577476A (en) A kind of Android system source code difference analysis method, server and medium based on Module Division
CN117667089A (en) Front-end form generation method and device, storage medium and electronic equipment
Chen et al. AST-Based Source Code Migration Through Symbols Replacement

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant