Method, device, equipment and medium for determining gender of code author
By obtaining a code dataset and dividing code style attributes based on sociological and psychological gender differences, and using a classifier to determine the gender of the code author, the problem of determining the gender of the code author in the existing technology is solved, and gender recognition with high accuracy is achieved.
Patent Information
- Application Number
- CN202310826029.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-07
- Publication Date
- 2025-09-16
- Estimated Expiration
- 2043-07-07
AI Technical Summary
There is a lack of effective methods in the existing technology to determine the gender of the code author. The text author gender determination method in natural language is not applicable to the determination of the gender of the code author.
By obtaining a code dataset, the style attributes of the code are divided based on gender differences in sociology and psychology, and the gender statistical information of the training samples corresponding to each style attribute is determined. The information is then input into a classifier for gender feature extraction, minimizing the deviation between the predicted gender and the labeled gender to train the classifier to determine the gender of the code author.
It effectively determines the gender of the code author and improves the accuracy of code author gender recognition, reaching 0.95 and 0.94, which is better than the method in the natural language field.
Smart Images

Figure CN116821344B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method, device, equipment and medium for determining the gender of a code author. Background Art
[0002] Generally, with the advancement of computer technology, application software is constantly being updated and iterated, and the open source community is thriving, leading to an increasing emphasis on cybersecurity. Tracing the source of cyberattacks and cracking down on the malicious code authors are crucial steps. Currently, malicious code can often be traced back to the virtual information (e.g., network ID) publicly available online by the malicious code author. Further tracing the malicious code author's real information requires analyzing their social attributes and improving their user profile in cyberspace. Furthermore, service providers can often use user profiles to provide personalized services to users across their services, such as personalized recommendations for service content based on user profiles. For code authors, identifying their gender is a fundamental part of user profiling.
[0003] While existing technologies for determining the gender of authors based on textual language are gradually developing in the natural language field, there is no effective solution for determining the gender of code authors in code. Natural language often carries emotional information in its vocabulary. Therefore, based on the differences in emotional expression between genders, the emotional tone of the text can be analyzed based on the emotional information in the vocabulary to determine the gender of the author. However, in code, code is a highly logical language, and code is often a logical product of problem solving. Therefore, methods for determining the gender of text authors in natural language are not suitable for determining the gender of code authors. Therefore, an effective method for determining the gender of code authors is urgently needed. Summary of the Invention
[0004] Based on this, it is necessary to provide a method, device, equipment and medium for determining the gender of the code author to address the above technical problems.
[0005] This manual adopts the following technical solutions:
[0006] This specification provides a method for determining the gender of a code author, including:
[0007] Obtain a code dataset, use each code segment in the dataset as a training sample, and annotate the gender of the author of each code segment;
[0008] Based on gender differences in sociology and psychology, we divide the style attributes of the code and determine the gender statistics of each style attribute for the training samples.
[0009] The gender statistics are spliced together and input into the classifier to extract gender features. The predicted gender of the code author is determined based on the obtained gender features.
[0010] With the optimization goal of minimizing the deviation between the predicted gender and the labeled gender, the classifier is trained using training samples; and the gender of the code author is determined using the trained classifier.
[0011] Optionally, the style attributes are divided into language features, structural features and layout features.
[0012] Optionally, for each style attribute, determining gender statistical information of the training sample corresponding to the style attribute specifically includes:
[0013] Based on the language characteristics, determine the frequency and importance of the author's customized names in the training samples;
[0014] Based on the structural characteristics, determine the occurrence frequency and cyclomatic complexity of different logical structures in the training samples;
[0015] Based on the layout features, the position information of each line of code in the training sample, the number of characters in each line of code, and the frequency of occurrence of the target characters are determined.
[0016] Optionally, determine the frequency and importance of author-defined names in the training samples, including:
[0017] The author-defined names in the training samples are represented by an abstract syntax tree, and the frequencies of occurrence of different nodes and edges in the obtained abstract syntax tree represent the frequencies of occurrence of the author-defined names in the training samples;
[0018] The importance of author-defined names in training samples is calculated based on the TF-IDF method.
[0019] Optionally, before splicing the gender statistical information and inputting the splicing information into a classifier for gender feature extraction, the method further includes:
[0020] For each style attribute, the gender statistical information of the training samples corresponding to the style attribute is divided according to gender, and the gender statistical information corresponding to different genders is obtained;
[0021] Construct the hypothesis that there is no difference between the gender statistics corresponding to different genders, and determine the conditions under which the hypothesis is valid;
[0022] Based on the Z statistics obtained according to the gender statistical information corresponding to different genders, the Kolmogorov-Smirnov value and the Shapiro-Wilk value were calculated;
[0023] According to the Kolmogorov-Smirnov value and Shapiro-Wilk value, determine whether the hypothesis is valid.
[0024] Optionally, the step of combining the gender statistical information and inputting the combined information into a classifier for gender feature extraction specifically includes:
[0025] When the assumption that there is no difference between the gender statistical information corresponding to different genders is not established, the gender statistical information is spliced and input into the classifier for gender feature extraction;
[0026] When the assumption that there is no difference between the gender statistical information corresponding to different genders is established, the operation of splicing the gender statistical information and inputting it into the classifier for gender feature extraction is not performed, and an interface is displayed to prompt the user to redetermine the gender statistical information corresponding to each style attribute of the training sample.
[0027] Optionally, the classifier is an AdaBoost classifier algorithm model obtained by using a CART decision tree as a weak classifier and combining each weak classifier, wherein the weights of the weak classifiers are obtained using a SAMME.R classification algorithm.
[0028] This specification provides a device for determining the gender of a code author, comprising:
[0029] The acquisition module is used to obtain a code dataset, use each code segment in the dataset as a training sample, and annotate the gender of the author of each code segment;
[0030] A classification module is used to classify code style attributes based on gender differences in sociology and psychology, and to determine the gender statistics of each style attribute for training samples.
[0031] The determination module is used to splice the gender statistical information of each group and input it into the classifier to extract gender features, and determine the predicted gender of the code author based on the obtained gender features;
[0032] The training application module is used to train the classifier using training samples with the optimization goal of minimizing the deviation between the predicted gender and the labeled gender; and to determine the gender of the code author using the trained classifier.
[0033] This specification provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it implements the above-mentioned code author gender determination method.
[0034] This specification provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, the above-mentioned method for determining the gender of the code author is implemented.
[0035] At least one of the above technical solutions adopted in this specification can achieve the following beneficial effects:
[0036] First, the code used as training samples and the annotated gender of the code author are determined. Then, based on gender differences in sociology and psychology, the style attributes of the code are divided, and the gender statistical information corresponding to each style attribute of the training samples is determined. After that, the gender statistical information is spliced and input into the classifier to determine the predicted gender of the code author. The classifier is trained with the optimization goal of minimizing the deviation between the predicted gender and the annotated gender, so that the gender of the code author can be determined through the trained classifier.
[0037] This solution is based on the manifestation of gender differences in code writing. It uses gender statistical information corresponding to style attributes that can reflect gender differences in code as input to train a classifier. This allows the trained classifier to learn the style attribute characteristics of different genders in the code, thereby effectively determining the gender of the code author. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0039] Figure 1 A flowchart of a method for determining the gender of a code author provided in this manual;
[0040] Figure 2 A schematic diagram of a device for determining the gender of a code author provided in this manual;
[0041] Figure 3 A schematic diagram of a computer device for implementing a method for determining the gender of a code author provided in this specification. DETAILED DESCRIPTION
[0042] To make the purpose, technical solutions, and advantages of this specification more clear, the technical solutions of this application will be clearly and completely described below in conjunction with the specific embodiments of this specification and the corresponding drawings. Obviously, the embodiments described are only part of the embodiments of this application, not all of them. Based on the embodiments in this specification, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0043] Currently, code, as a programming language, is learned, just like natural language. Furthermore, both code and natural language are acquired by individuals through long-term social learning and physiological environments, and both possess relatively stable linguistic characteristics. Research in natural language processing has shown that different authors have distinct written styles, so analyzing the linguistic characteristics of text can be used to trace the author's identity. Similarly, different programmers may use different writing styles when writing code with the same meaning. Therefore, it is possible to trace the gender of a code author through the high-dimensional characteristics of the code.
[0044] People's use of natural language varies depending on sociological characteristics such as region, society, and gender. Programming language (source code), as a form of language, is also influenced by the sociological characteristics of its authors. Linguistic researchers have long sought to identify and explain potential differences in language styles between genders. The study of gendered language dates back to ancient Greece and Rome. However, current research on code primarily focuses on identifying authorship, with little effort devoted to mapping code's social attributes based on the author's sociological attributes.
[0045] In the natural language field, the sentiment of text and the gender of the text author can be analyzed based on the sentiment information of vocabulary. However, in the code space, code is a logical product of problem solving. The current difficulty lies in discovering which code file features can be related to the gender of the code author, and how to match the code file features with the code author's gender.
[0046] Currently, code author attribution is a major area of analysis in the code field. However, there is currently no effective solution for identifying the gender of code authors. Directly applying existing natural language methods for identifying the gender of text authors to code gender identification is not advisable. What model is suitable for identifying the gender of code authors, and how can natural language methods be used as a reference to implement code author gender identification? This is why existing code author gender identification is so difficult.
[0047] This approach links code with the sociological attribute of gender, identifying mappings and exploring their implications. In today's society, people have a more diverse understanding of gender. Twitter categorizes user gender into nine different categories, and Facebook even offers 97 gender registration options. Due to concerns about personal privacy and the relatively small number of diverse gender groups, collecting diverse data is difficult. Therefore, we define gender identification as a binary classification task, considering only the traditional two genders: male and female. This provides a method for determining the gender of code authors.
[0048] The following describes in detail the technical solutions provided by various embodiments of the present application in conjunction with the accompanying drawings.
[0049] Figure 1 The following is a flowchart of a method for determining the gender of a code author in this specification, which specifically includes the following steps:
[0050] S101: Obtain a code dataset, use each code segment in the dataset as a training sample, and annotate the gender of the author of each code segment.
[0051] Generally, the server of the business platform can create user profiles based on business data. When implementing code author user profiles by determining the gender of the code author, the server can first train the algorithm model through the data set, and then determine the gender of the code author through the trained algorithm model.
[0052] Therefore, in one or more embodiments of the present specification, the server of the business platform may first obtain a data set, use each code segment in the data set as a training sample, and mark the gender of the author of each code segment in the data set, so as to train the algorithm model subsequently adopted through the training samples and the marked gender.
[0053] The data set may be collected in advance by the server, or may be obtained through a third-party platform. The specific method may be determined according to needs, and this specification does not impose any restrictions on this.
[0054] The server mentioned in this specification can be a server set up on a business platform, or a device such as a desktop computer or a laptop computer that can execute the solution of this specification. For the sake of convenience, the following description will only take the server as the execution subject.
[0055] S102: Based on gender differences in sociology and psychology, the style attributes of the code are divided, and gender statistical information corresponding to each style attribute of the training samples is determined.
[0056] After obtaining the training samples and their corresponding annotations, the server can first classify the code into style attributes, wherein the style attributes represent the habitual preferences that the code author may exhibit in several aspects during the writing process.
[0057] Based on gender differences in sociology and psychology, different genders often have different vocabulary preferences when writing texts. For example, men tend to use words that convey information, while women tend to use the first-person singular. Therefore, in one or more embodiments of this specification, when migrating to code, language features such as custom naming or custom code descriptions that reflect the code author's personal style can be selected to determine the code author's gender based on the differences in language features between different genders.
[0058] Furthermore, the embodied cognition theory of language is to apply the embodied cognition theory to the processing and understanding of language. From the embodied cognition view of language, it can be seen that human understanding of the concept of things does not come from abstract propositional representations, but from a specific body perception system. Therefore, the "specific body perception system", such as gender, can be inferred from the logic and structure of the code written by the author. That is, the differences in thinking between men and women can be reflected in the structure of the code. Therefore, in one or more embodiments of this specification, structural features that can reflect the personal style of the code author can also be selected, so as to determine the gender of the code author based on the differences in structural features between different genders.
[0059] Furthermore, sociology and psychology show that men and women also have different stylistic habits in writing and handwriting. For example, compared to men, women's handwriting is generally neater and their layout is more refined. This is reflected in the layout of the code. Therefore, in one or more embodiments of this specification, layout features that reflect the code author's personal style can also be selected, thereby determining the code author's gender based on the differences in layout features between different genders.
[0060] For example, analyzing language features using author-defined identifiers or code annotations in a dataset reveals that, in the specific context of the target code file, women tend to use more words like "world," "factory," and "end," while men tend to use more words like "resource" and "get." The specific context here refers to the target code file being written by the author to solve a specific problem. Compared to the content of the code dataset, the target code file belongs to a specific context.
[0061] Regarding structural features, in specific scenarios, the average frequency of local variable use among men was 0.0912, while the average frequency among women was 0.12, indicating that women tend to use local variables more frequently. The average frequency of ternary operators used by men in their code was 0.88, while the average frequency among women was 0.594, indicating that men tend to use ternary operators more frequently. Further analysis revealed that women tend to use camelCase more frequently, while men tend to use it more frequently for function parameters.
[0062] As for layout features, in specific scenarios, the differences between men and women in typesetting layout are fully reflected in the use of whitespace characters (number of blank lines, spaces and tabs), format preferences (whether the file starts with a tab or a space), line length, etc.
[0063] Therefore, in one or more embodiments of this specification, the style attributes of the code can be divided into language features, structural features, and layout features. Among them, language features refer to the custom naming preferences of the code author during the code writing process. The custom naming mentioned here includes but is not limited to custom naming of variables, custom naming of functions or methods, custom naming of files, etc. Structural features refer to the usage preferences and organizational preferences of different logical structures, for example, the usage preferences for single selection structure, double selection structure, and multiple selection structure in the selection structure, the nested organization of loop structure, the depth of loop, etc. Layout features refer to the overall structure of the code, for example, the length of each line of code, the use of whitespace characters, various preferences, etc.
[0064] It is understandable that each style attribute may include different information types. Taking syntactic features as an example, syntactic features may include at least two information types: selection structure and loop structure. Among them, the selection structure may include three information types: single selection structure, double selection structure, and multiple selection structure.
[0065] Therefore, for the various style attributes mentioned above, the server can determine the gender statistical information of the training samples corresponding to each style attribute, wherein the gender statistical information mentioned here refers to the statistical information corresponding to the style attribute that can reflect gender differences, and the gender statistical information can be comprehensive gender statistical information of different information types included in the style attribute.
[0066] Furthermore, in one or more embodiments of the present specification, with respect to language features, the server may determine the frequency of occurrence and importance of the author's custom naming in the training sample. With respect to structural features, the frequency of occurrence of different logical structures and the cyclomatic complexity of different logical structures in the training sample are determined. With respect to layout features, the location information of each line of code in the training sample, the number of characters in each line of code, and the frequency of occurrence of target characters are determined. Among them, the server may represent the author's custom naming in the training sample through an abstract syntax tree, use the frequency of occurrence of different nodes and edges in the obtained abstract syntax tree to represent the frequency of occurrence of the author's custom naming in the training sample, and calculate the importance of the author's custom naming in the training sample based on the TF-IDF method. Gender statistical information for various style attributes can be represented in the form of vectors.
[0067] Of course, the author's custom names in the code are usually very numerous. In one or more embodiments of this specification, the server can use the TF-IDF value to filter the most representative words for each code file or each code segment, and select the top k items with the largest total TF-IDF value to form a feature vector corresponding to the language feature.
[0068] The above description of the division of the style attributes of the code and the determination of the gender statistical information of the training samples corresponding to each style attribute is only an example description, and can be set specifically as needed, and this specification does not impose any restrictions on this.
[0069] S103: The gender statistical information is spliced and input into a classifier to extract gender features, and the predicted gender of the code author is determined based on the obtained gender features.
[0070] S104: Minimizing the deviation between the predicted gender and the labeled gender is used as an optimization goal, and the classifier is trained to determine the gender of the code author through the trained classifier.
[0071] After obtaining the gender statistical information corresponding to each style attribute of the training sample, the server can splice the gender statistical information and input it into the classifier to extract gender features, and determine the predicted gender of the code author based on the obtained gender features.
[0072] The splicing of the statistical information of each gender, that is, the splicing of the vectors corresponding to the statistical information of each gender, is described by taking the style attributes including layout features, lexical features, and syntactic features as an example. The splicing of the statistical information of each gender is specifically as follows:
[0073]
[0074] Where, is the final feature vector of the training sample, is a vector of gender statistics corresponding to language features, is the vector of gender statistics corresponding to the structural features, A vector of gender statistics corresponding to layout features.
[0075] The classifier can be any existing, relatively mature classifier algorithm model. The specific classifier algorithm model used can be determined based on needs and is not limited in this specification. The gender feature here is derived by the classifier by concatenating the input statistical information for each gender and extracting the features. The techniques for extracting features from input data are well-established and will not be further elaborated here.
[0076] In one or more embodiments of this specification, preferably, the server can use a CART decision tree as a weak classifier and combine the weak classifiers to obtain an AdaBoost classifier algorithm model, wherein the weights of the weak classifiers can be obtained using the SAMME.R classification algorithm, and in the process of training the classifier using training samples, a ten-fold cross-validation test method can be used to minimize the deviation between the predicted gender and the labeled gender as the optimization goal, and the classifier can be trained through multiple rounds of iterations. Specifically, the classification algorithm model can be constructed using entropy and information gain using the following formula:
[0077]
[0078]
[0079]
[0080] in, For collection The information entropy of For collection In the information type Information conditional entropy under given conditions, For collection Information entropy With collection In the information type Information conditional entropy under given conditions difference. represents a dataset, For the dataset The size of , that is, the number of samples, For gender type, , taking the division of gender including male and female as an example, then , A gender type, Belong to gender category The number of samples, .
[0081] As can be seen from the above, each style attribute can include different information types, and the gender statistical information of the training sample corresponding to each style attribute can be the comprehensive gender statistical information corresponding to the different information types included in the style attribute. is an information type in a style attribute, for example, the ternary operator in the structural feature. According to the gender statistics of the corresponding ternary operator, different samples may have different numbers of ternary operators. So the information type can be set have Different values , assuming ,but Indicates that there are two ternary operators in the sample.
[0082] Therefore, according to the characteristics The value of the dataset Divided into Subset , ,……, , For the dataset Existence Information Type A sample of For the dataset Existence Information Type The number of samples, continuing with the above example, the subset Representation dataset There are 2 samples of ternary operators in Representing a dataset The number of samples with 2 ternary operators.
[0083] After the training of the classifier is completed, when the server obtains an unknown code whose author is to be determined, it can first determine the feature vector composed of the gender statistical information of each style attribute corresponding to the unknown code, and then splice the feature vectors and input them into the trained classifier, so as to determine the gender of the code author through the classifier.
[0084] based on Figure 1 The method for determining the gender of code authors shown in the figure first determines the code used as training samples and the annotated gender of the code author. Then, based on gender differences in sociology and psychology, the style attributes of the code are divided, and gender statistical information corresponding to each style attribute of the training samples is determined. Subsequently, the gender statistical information is concatenated and input into a classifier to determine the predicted gender of the code author. The classifier is trained with minimizing the deviation between the predicted gender and the annotated gender as the optimization goal, so that the gender of the code author can be determined using the trained classifier.
[0085] This solution is based on the manifestation of gender differences in code writing. It uses gender statistical information corresponding to style attributes that can reflect gender differences in code as input to train a classifier. This allows the trained classifier to learn the style attribute characteristics of different genders in the code, thereby effectively determining the gender of the code author.
[0086] When applying the code author gender determination method provided in this manual, it is not necessary to Figure 1 The steps are executed in the order shown. The specific execution order of the steps can be determined according to needs and this manual does not limit this.
[0087] Furthermore, in one or more embodiments of this specification, as described in step S102, each style attribute can include different types of information. Therefore, differences in gender statistics corresponding to each style attribute between different authors may be due to either author differences or gender differences. Therefore, to further improve the accuracy of the code author gender determination method, usability analysis of the gender statistics corresponding to each style attribute can be performed using statistical hypothesis testing methods.
[0088] Specifically, in one or more embodiments of this specification, the server may, for each style attribute, divide the gender statistical information of the training samples determined to correspond to the style attribute based on gender, thereby obtaining gender statistical information corresponding to different genders. In other words, the gender statistical information may be divided into gender statistical information corresponding to males and gender statistical information corresponding to females. Of course, since each style attribute may include different information types, the division herein may be further divided according to different information types.
[0089] The server then constructs a hypothesis that there are differences between the gender statistics corresponding to different genders and determines the conditions under which the hypothesis holds true. The null hypothesis is that there are no differences between the gender statistics corresponding to different genders, while the alternative hypothesis is that there are differences between the gender statistics corresponding to different genders. The conditions under which the hypothesis holds true depend on the hypothesis testing method selected.
[0090] Secondly, the server can calculate the Kolmogorov-Smirnov value (KS) and the Shapiro-Wilk value (SW) based on the Z statistic obtained according to the gender statistical information corresponding to different genders. Finally, the server can determine whether the hypothesis is valid based on the Kolmogorov-Smirnov value and the Shapiro-Wilk value.
[0091] The Z statistic corresponds to the Z test selected in this solution. The KS test can be used to analyze whether there is a significant difference between two distributions. The SW test is a normal distribution test. The SW value can be used to determine whether the gender statistics corresponding to different genders conform to a normal distribution. If so, the KS test can be performed based on the Z statistic to determine whether there is a significant difference between the gender statistics corresponding to males and females due to gender differences.
[0092] For example, suppose the KS value obtained from the training sample is 0.001 and the SW value is 0.011. The data conforms to the normal distribution and according to the KS result, its significance is 0.001 < 0.05. Therefore, the null hypothesis is rejected. In other words, due to gender differences, there are differences between the gender statistics of different genders. The gender of the code author can be determined based on the existing gender statistics.
[0093] Furthermore, in one or more embodiments of the present specification, when the assumption that there are differences between the gender statistical information corresponding to different genders in the above judgment is established, the server may splice the gender statistical information and input it into the classifier for gender feature extraction. When subsequently determining the gender of the code author of the unknown code, it is also determined only based on the gender statistical information corresponding to the established assumption, thereby further improving the accuracy of determining the gender of the code author.
[0094] When the assumption that there is no difference between the gender statistical information corresponding to different genders is established, the server may not perform the operation of splicing the gender statistical information and inputting it into the classifier for gender feature extraction, but display an interface for prompting the user to redetermine the gender statistical information corresponding to each style attribute of the training sample.
[0095] In other words, when a hypothesis test determines that there are no significant differences between the gender statistics corresponding to different genders, this indicates that some information types within the gender statistics corresponding to the style attributes do not reflect gender differences. The user can then be prompted to remove the gender statistics corresponding to the information types that do not reflect gender differences. Finally, only the gender statistics corresponding to the different information types within each style attribute that can reflect gender differences are concatenated and input into the classifier for training. Subsequently, when determining the gender of the code author of unknown code, this determination is also made based solely on the gender statistics corresponding to the different information types within each style attribute that can reflect gender differences, further improving the accuracy of determining the code author's gender.
[0096] In addition, one or more embodiments of this specification also provide an application embodiment of this solution. Since the industry currently lacks similar technologies for code author gender identification methods, this embodiment uses methods in the natural language field to perform code author identification as a comparison, and illustrates the effectiveness of this solution by comparing its performance on the GitHub-gender-C++ dataset and the GitHub-gender-Java dataset.
[0097] After training on both datasets using the same process, our solution achieved an accuracy of 0.95 and 0.94 for author gender identification, respectively. Using the CBOW method in the natural language domain, we achieved accuracy rates of 0.85 and 0.86, respectively. This demonstrates that our solution has a higher accuracy for determining code author gender.
[0098] The above is a method for determining the gender of a code author provided in one or more embodiments of this specification. Based on the same idea, this specification also provides a corresponding device for determining the gender of a code author, such as Figure 2 shown.
[0099] Figure 2 A schematic diagram of a device for determining the gender of a code author provided in this specification includes:
[0100] The acquisition module 201 is used to obtain a code data set, use each code segment in the data set as a training sample, and determine the labeled gender of the author of each code segment;
[0101] A classification module 202 is configured to classify the style attributes of the code based on gender differences in sociology and psychology, and determine gender statistics of the training samples corresponding to each style attribute;
[0102] Determination module 203, for combining the gender statistics and inputting them into a classifier to extract gender features, and determining the predicted gender of the code author based on the obtained gender features;
[0103] The training application module 204 is used to train the classifier using training samples with the optimization goal of minimizing the deviation between the predicted gender and the labeled gender; and to determine the gender of the code author using the trained classifier.
[0104] Optionally, style attributes are divided into language features, structural features, and layout features.
[0105] Optionally, the division module 202 determines the frequency of occurrence and importance of the author's customized names in the training sample based on the language features, determines the frequency of occurrence of different logical structures and the cyclomatic complexity of different logical structures in the training sample based on the structural features, and determines the position information of each line of code in the training sample, the number of characters in each line of code, and the frequency of occurrence of target characters based on the layout features.
[0106] Optionally, the division module 202 represents the author-customized names in the training sample through an abstract syntax tree, uses the frequency of occurrence of different nodes and edges in the obtained abstract syntax tree to represent the frequency of occurrence of the author-customized names in the training sample, and calculates the importance of the author-customized names in the training sample based on the TF-IDF method.
[0107] Optionally, the device also includes: an analysis module 205, which is used to divide the gender statistical information of the training samples corresponding to each style attribute according to gender, obtain gender statistical information corresponding to different genders, construct a hypothesis that there is no difference between the gender statistical information corresponding to different genders, and determine the conditions for the hypothesis to be true, calculate the Kolmogorov-Smirnov value and the Shapiro-Wilk value based on the Z statistic obtained from the gender statistical information corresponding to different genders, and judge whether the hypothesis is true based on the Kolmogorov-Smirnov value and the Shapiro-Wilk value.
[0108] Optionally, the determination module 203, when the assumption that there is no difference between the gender statistical information corresponding to different genders is not established, splices the gender statistical information and inputs it into the classifier for gender feature extraction; when the assumption that there is no difference between the gender statistical information corresponding to different genders is established, does not perform the operation of splicing the gender statistical information and inputting it into the classifier for gender feature extraction, and displays an interface for prompting the user to redetermine the gender statistical information corresponding to each style attribute of the training sample.
[0109] Optionally, the classifier is an AdaBoost classifier algorithm model obtained by using a CART decision tree as a weak classifier and combining each weak classifier, wherein the weights of the weak classifiers are obtained using a SAMME.R classification algorithm.
[0110] The specific limitations of the code author gender determination device can be found in the limitations of the code author gender determination method described above and will not be further elaborated here. Each module in the aforementioned code author gender determination device can be implemented in whole or in part through software, hardware, or a combination thereof. Each of these modules can be embedded in or independent of a processor in a computer device in hardware form, or stored in a computer device memory in software form, so that the processor can call and execute the corresponding operations of each of these modules.
[0111] This specification also provides a computer-readable storage medium, which stores a computer program that can be used to execute the above Figure 1 Gender determination method for code authors provided.
[0112] This manual also provides Figure 3 The structural diagram of the computer equipment shown in FIG. Figure 3 As mentioned above, at the hardware level, the computer device includes a processor, an internal bus, a network interface, a memory, and a non-volatile memory, and may also include other hardware required for the business. The processor reads the corresponding computer program from the non-volatile memory into the memory and then runs it to achieve the above Figure 1 Gender determination method for code authors provided.
[0113] Those skilled in the art will appreciate that all or part of the processes in the above-described method embodiments can be implemented by instructing the relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the above-described method embodiments. Any reference to memory, storage, database, or other media used in the embodiments provided herein may include at least one of non-volatile and volatile memory. Non-volatile memory may include read-only memory (ROM), magnetic tape, floppy disk, flash memory, or optical storage. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM).
[0114] The technical features of the above embodiments can be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
Claims
1. A method for determining the gender of a code author, characterized in that: include: Obtain a code dataset, use each code segment in the dataset as a training sample, and annotate the gender of the author of each code segment; Based on gender differences in sociology and psychology, we divide the style attributes of the code and determine the gender statistics of each style attribute for the training samples. For each style attribute, the gender statistical information of the training samples corresponding to the style attribute is divided according to gender, and the gender statistical information corresponding to different genders is obtained; Construct the hypothesis that there is no difference between the gender statistics corresponding to different genders, and determine the conditions under which the hypothesis is valid; Based on the Z statistics obtained according to the gender statistical information corresponding to different genders, the Kolmogorov-Smirnov value and the Shapiro-Wilk value were calculated; According to the Kolmogorov-Smirnov value and Shapiro-Wilk value, determine whether the hypothesis is valid; When the assumption is not true, the gender statistics are concatenated and input into the classifier to extract gender features. The predicted gender of the code author is determined based on the obtained gender features. With the optimization goal of minimizing the deviation between the predicted gender and the labeled gender, the classifier is trained using training samples; and the gender of the code author is determined using the trained classifier.
2. The method for determining the gender of a code author according to claim 1, wherein: The style attributes are divided into language features, structural features and layout features.
3. The method for determining the gender of a code author according to claim 2, wherein: Determining gender statistics of each style attribute corresponding to the training sample specifically includes: Based on the language characteristics, determine the frequency and importance of the author's customized names in the training samples; Based on the structural characteristics, determine the occurrence frequency and cyclomatic complexity of different logical structures in the training samples; Based on the layout features, the position information of each line of code in the training sample, the number of characters in each line of code, and the frequency of occurrence of the target characters are determined.
4. The method for determining the gender of a code author according to claim 3, wherein: Determine the frequency and importance of author-defined names in the training samples, including: The author-defined names in the training samples are represented by an abstract syntax tree, and the frequencies of occurrence of different nodes and edges in the obtained abstract syntax tree represent the frequencies of occurrence of the author-defined names in the training samples; The importance of author-defined names in training samples is calculated based on the TF-IDF method.
5. The method for determining the gender of a code author according to claim 1, wherein: The step of combining the statistical information of each gender and inputting it into the classifier to extract gender features specifically includes: When the assumption that there is no difference between the gender statistical information corresponding to different genders is not established, the gender statistical information is spliced and input into the classifier for gender feature extraction; When the assumption that there is no difference between the gender statistical information corresponding to different genders is established, the operation of splicing the gender statistical information and inputting it into the classifier for gender feature extraction is not performed, and an interface is displayed to prompt the user to redetermine the gender statistical information corresponding to each style attribute of the training sample.
6. The method for determining the gender of a code author according to claim 1, wherein: The classifier is an AdaBoost classifier algorithm model obtained by using a CART decision tree as a weak classifier and combining the weak classifiers, wherein the weights of the weak classifiers are obtained using a SAMME.R classification algorithm.
7. A device for determining the gender of a code author, characterized in that: include: The acquisition module is used to obtain a code dataset, use each code segment in the dataset as a training sample, and annotate the gender of the author of each code segment; A classification module is used to classify code style attributes based on gender differences in sociology and psychology, and to determine the gender statistics of each style attribute for training samples. An analysis module is used to divide the gender statistical information of the training samples corresponding to each style attribute according to gender, thereby obtaining gender statistical information corresponding to different genders; construct a hypothesis that there is no difference between the gender statistical information corresponding to different genders, and determine the conditions under which the hypothesis is true; Based on the Z statistics obtained according to the gender statistical information corresponding to different genders, the Kolmogorov-Smirnov value and the Shapiro-Wilk value were calculated; According to the Kolmogorov-Smirnov value and Shapiro-Wilk value, determine whether the hypothesis is valid; The determination module is used to splice the gender statistics of each unit and input them into the classifier to extract gender features when the hypothesis is not established. The predicted gender of the code author is determined based on the obtained gender features. The training application module is used to train the classifier using training samples with the optimization goal of minimizing the deviation between the predicted gender and the labeled gender; and to determine the gender of the code author using the trained classifier.
8. A computer-readable storage medium, characterized in that The storage medium stores a computer program, and when the computer program is executed by a processor, the method for determining the gender of the code author according to any one of claims 1 to 6 is implemented.
9. A computer device, characterized in that: The method comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the method for determining the gender of the code author according to any one of claims 1 to 6 is implemented.