Method, server, terminal and electronic equipment for online food risk control
By combining the pre-trained risk identification model and the BERT model with pinyin text and attention mechanism, the problems of low efficiency and accuracy in the review of food safety issues in restaurant reviews by Internet platforms were solved, and efficient and accurate food safety risk identification was achieved.
Patent Information
- Application Number
- CN202111670988.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-31
- Publication Date
- 2025-09-26
- Estimated Expiration
- 2041-12-31
AI Technical Summary
In the existing technology, the efficiency of Internet platforms in reviewing food safety issues in restaurant reviews is low and cannot meet timeliness requirements. In addition, manual review has difficulty in accurately identifying Chinese semantics and typos, resulting in misidentification and missed recognition.
A pre-trained risk identification model is used to obtain comment text and keyword text, and the BERT model is used for rating and attribution analysis. Combined with pinyin text and attention mechanism, the highest risk level and attribution analysis results of food safety are identified.
It has greatly improved the efficiency and accuracy of food safety risk identification, can quickly identify high-risk events, and provide precise guarantees for subsequent early warning and risk management.
Smart Images

Figure CN114429284B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of natural language processing technology. Specifically, the present application relates to a method, server, terminal and electronic device for online food risk control. Background Art
[0002] With the rise of the catering industry, there are more and more public opinions involving food safety, and the public is paying more and more attention to food safety issues.
[0003] For Internet platforms that provide catering services, they are the liaison between merchants and customers in the catering industry. Therefore, it is necessary to provide feedback on customers' comments after meals and promptly discover food safety issues that may occur during the meal.
[0004] Existing technologies often require internet platforms to manually review food safety issues pointed out in comments. However, due to the low efficiency of manual review, even highly professional manual reviewers take 15-30 seconds, which cannot meet the timeliness requirements when faced with billions of data points every day. Summary of the Invention
[0005] Embodiments of the present invention provide a method, device, electronic device, and storage medium for online food risk control that overcome the above-mentioned problems or at least partially solve the above-mentioned problems.
[0006] In a first aspect, a method for online food risk control is provided, the method comprising:
[0007] Obtaining comment text and keyword text, wherein the keyword text includes keywords corresponding to various attribution analysis results related to food safety;
[0008] Inputting the review text and keyword text into a pre-trained risk identification model to obtain the highest food safety risk level of the review text and a target attribution analysis result output by the risk identification model;
[0009] The risk identification model is trained using sample review texts and keyword texts related to catering as training samples, and the highest food safety risk level and attribution analysis results of the sample review texts as training labels.
[0010] In one possible implementation, the risk identification model includes a rating model;
[0011] Inputting the review text into a pre-trained risk identification model to obtain the highest food safety risk level and attribution analysis result of the review text output by the risk identification model includes:
[0012] Inputting the review text and the corresponding pinyin text into the grading model to obtain the highest food safety risk level of the review text output by the grading model;
[0013] The grading model is trained based on the sample review text and the corresponding pinyin text as training samples, and the highest food safety risk level of the sample review text as a training label.
[0014] In a possible implementation, the rating model is further configured to output a CLS vector; wherein the highest risk level is determined according to the CLS vector.
[0015] In one possible implementation, the risk identification model also includes an attribution model;
[0016] Inputting the review text into a pre-trained risk identification model to obtain the highest food safety risk level and attribution analysis result of the review text output by the risk identification model includes:
[0017] Inputting the comment text, the CLS vector, and a preset keyword text into the attribution model to obtain a target attribution analysis result of the comment text output by the attribution model;
[0018] The attribution model is trained based on the sample comment text, keyword text and the CLS vector of the sample comment text output by the rating model as training samples, and the attribution analysis results of the sample comment text as training labels.
[0019] In one possible implementation, the rating model includes an input layer, a pre-trained language model, and a classification layer;
[0020] Inputting the review text and the corresponding pinyin text into the grading model to obtain the CLS vector output by the grading model and the highest food safety risk level of the review text includes:
[0021] Inputting the comment text and the corresponding pinyin text into the input layer, obtaining a first word segmentation sequence output by the input layer after character-level segmentation of the comment text and a second word segmentation sequence output by the input layer after character-level segmentation of the pinyin text;
[0022] Inputting the first segmentation sequence and the second segmentation sequence into the pre-trained language model to obtain a vector representation of each segmentation in the review text output by the pre-trained language model after integrating the semantic information of the full text;
[0023] The vector representation is input into the classification layer to obtain the CLS vector output by the classification layer after pooling, activation function and full connection processing, as well as the highest risk level of the comment text.
[0024] In one possible implementation, the pre-trained language model is a BERT model, wherein the BERT model includes a first embedding layer, a second embedding layer, and a transformer layer;
[0025] Inputting the first word segmentation sequence and the second word segmentation sequence into the pre-trained language model to obtain the vector representation of the review text output by the pre-trained language model includes:
[0026] Input the first word segmentation sequence into the first embedding layer, and obtain the word embedding vector, segment embedding vector, and position embedding vector of the comment text output by the first embedding layer;
[0027] Inputting the second word segmentation sequence into the second embedding layer to obtain the pinyin embedding vector of the comment text output by the second embedding layer;
[0028] The word embedding word embedding vector, segment embedding segment embedding vector, position embeddings position embedding vector and pinyin embedding vector are input into the transformer layer to obtain the vector representation output by the transformer layer.
[0029] In one possible implementation, inputting the second word segmentation sequence into the second embedding layer to obtain the pinyin embedding vector of the comment text output by the second embedding layer includes:
[0030] For each word in the second word segmentation sequence, determine the corresponding unique identifier from a preset dictionary, input the unique identifier into the BertModel class source code for compilation, and obtain the pinyin embedding vector;
[0031] The preset dictionary includes at least one word segment and a corresponding unique identifier.
[0032] In one possible implementation, the attribution model includes a word vector layer, a first attention mechanism layer, a second attention mechanism layer, and a classification layer;
[0033] Inputting the comment text, the CLS vector, and the keyword text into the attribution model to obtain the food safety attribution analysis result of the comment text output by the attribution model includes:
[0034] Input the comment text and keyword text into the word vector layer respectively, and obtain the first word vector of the comment text and the second word vector of the keyword text output by the word vector layer;
[0035] Inputting the first word vector and the second word vector into a first attention mechanism layer to obtain a first attention weight of the comment text;
[0036] Inputting the CLS vector and the second word vector into the second attention mechanism layer to obtain the second attention weight of the comment text;
[0037] The first attention weight and the second attention weight are input into the classification layer, and the classification layer outputs the target attribution analysis result of the comment text.
[0038] Secondly, a method for controlling food risks online is provided, including:
[0039] Displaying a comment editing interface, wherein the comment editing interface displays the comment text to be published;
[0040] In response to a comment publishing operation for the comment text, the published comment text, as well as the highest food safety risk level and target attribution analysis results of the comment text are displayed.
[0041] In a possible implementation, the published comment text, the highest food safety risk level of the comment text, and the target attribution analysis results are displayed, and the following is also included before:
[0042] Inputting the review text and preset keyword text into a pre-trained risk identification model to obtain the highest food safety risk level of the review text and target attribution analysis results output by the risk identification model;
[0043] The keyword text includes keywords corresponding to various attribution analysis results of food safety;
[0044] The risk identification model is trained using sample review texts and keyword texts related to catering as training samples, and the highest food safety risk level and attribution analysis results of the sample review texts as training labels.
[0045] In one possible implementation, the risk identification model includes a rating model;
[0046] Inputting the review text into a pre-trained risk identification model to obtain the highest food safety risk level and attribution analysis result of the review text output by the risk identification model includes:
[0047] Inputting the review text and the corresponding pinyin text into the grading model to obtain the highest food safety risk level of the review text output by the grading model;
[0048] The grading model is trained based on the sample review text and the corresponding pinyin text as training samples, and the highest food safety risk level of the sample review text as a training label.
[0049] In a possible implementation, the rating model further outputs a CLS vector; wherein the highest risk level is determined according to the CLS vector.
[0050] In one possible implementation, the risk identification model further includes an attribution model;
[0051] Inputting the review text into a pre-trained risk identification model to obtain the highest food safety risk level of the review text and a target attribution analysis result output by the risk identification model includes:
[0052] Inputting the comment text, CLS vector, and preset keyword text into the attribution model to obtain a target attribution analysis result of the comment text output by the attribution model;
[0053] The attribution model is trained based on the sample comment text, keyword text and the CLS vector of the sample comment text output by the rating model as training samples, and the attribution analysis results of the sample comment text as training labels.
[0054] In one possible implementation, the following is also included:
[0055] Displaying a meal ordering interface, which includes food risk information of the ordering merchant;
[0056] The food risk information includes at least one of the following:
[0057] The number of food safety incidents at each risk level for the ordering merchant within a preset time period;
[0058] The proportion of food safety incidents occurring at the aforementioned ordering merchants; and
[0059] The food safety rating of the ordering merchant.
[0060] In a third aspect, a server is provided, including:
[0061] A text acquisition module, configured to acquire comment text and keyword text, wherein the keyword text includes keywords corresponding to various attribution analysis results related to food safety;
[0062] A risk identification module is used to input the review text and keyword text into a pre-trained risk identification model to obtain the highest food safety risk level of the review text and the target attribution analysis result output by the risk identification model;
[0063] The risk identification model is trained using sample review texts and keyword texts related to catering as training samples, and the highest food safety risk level and attribution analysis results of the sample review texts as training labels.
[0064] In a fourth aspect, a terminal is provided, including:
[0065] An interface display module is used to display a comment editing interface, in which the comment text to be published is displayed;
[0066] The analysis result display module is used to respond to the comment publishing operation on the comment text and display the comment text after publishing, as well as the highest food safety risk level and target attribution analysis results of the comment text.
[0067] In a fifth aspect, an embodiment of the present invention provides an electronic device comprising 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 steps of the method provided in the first or second aspect are implemented.
[0068] In a sixth aspect, an embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the method provided in the first or second aspect.
[0069] In the seventh aspect, an embodiment of the present invention provides a computer program, which includes computer instructions, and the computer instructions are stored in a computer-readable storage medium. When the processor of a computer device reads the computer instructions from the computer-readable storage medium, the processor executes the computer instructions, so that the computer device performs the steps of implementing the method provided in the first or second aspect.
[0070] The method, server, terminal and electronic device for online food risk control provided by the embodiments of the present invention can obtain the food safety risk level and target attribution analysis results of the comment text by obtaining comment text and keyword text, and inputting the comment text and keyword text into a pre-trained risk identification model. Compared with the manual identification method of the existing technology, it not only greatly improves the recognition efficiency, but also can accurately identify the attribution analysis results, that is, the keywords in the comment text that reflect the highest risk level, laying the foundation for subsequent rapid early warning of high-risk food safety incidents, accurate protection of consumer food safety complaints, and accurate risk management of catering service providers. BRIEF DESCRIPTION OF THE DRAWINGS
[0071] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for describing the embodiments of the present application.
[0072] Figure 1 A diagram illustrating the application environment of the online food risk control method provided in an embodiment of the present application;
[0073] Figure 2 A flow chart of the method for online food risk control provided in an embodiment of the present application;
[0074] Figure 3 A schematic diagram of a meal ordering page provided in an embodiment of the present application;
[0075] Figure 4 A schematic diagram of a review page provided in an embodiment of the present application;
[0076] Figure 5 A flow chart of a method for online food risk control using a risk identification model provided in an embodiment of the present application;
[0077] Figure 6 A schematic diagram of the structure of the rating model provided in the embodiment of the present application;
[0078] Figure 7 A schematic diagram of the structure of the pre-trained language model provided in an embodiment of the present application;
[0079] Figure 8 A schematic diagram of a process for outputting target attribution analysis results through an attribution model provided in an embodiment of the present application;
[0080] Figure 9 A flowchart of a method for online food risk control provided by another embodiment of the present application;
[0081] Figure 10 A schematic diagram of the structure of a server provided in an embodiment of the present application;
[0082] Figure 11 A schematic diagram of the structure of a terminal provided in an embodiment of the present application;
[0083] Figure 12 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0084] The following describes the embodiments of the present application in conjunction with the accompanying drawings. It should be understood that the embodiments described below in conjunction with the accompanying drawings are exemplary descriptions for explaining the technical solutions of the embodiments of the present application and do not constitute a limitation on the technical solutions of the embodiments of the present application.
[0085] Those skilled in the art will understand that, unless otherwise stated, the singular forms "a", "an", "said", and "the" used herein may also include plural forms. It should be further understood that the terms "including" and "comprising" used in the embodiments of the present application mean that the corresponding features can be implemented as the presented features, information, data, steps, operations, elements, and / or components, but do not exclude implementation as other features, information, data, steps, operations, elements, components, and / or combinations thereof supported by the present technical field. It should be understood that when we say that an element is "connected" or "coupled" to another element, the element can be directly connected or coupled to the other element, or it can refer to the element and the other element establishing a connection relationship through an intermediate element. In addition, the "connection" or "coupling" used here can include wireless connection or wireless coupling. The term "and / or" used here indicates at least one of the items defined by the term, for example, "A and / or B" can be implemented as "A", or as "B", or as "A and B".
[0086] In order to make the objectives, technical solutions and advantages of this application clearer, the implementation methods of this application will be further described in detail below with reference to the accompanying drawings.
[0087] First, several terms involved in this application are introduced and explained:
[0088] 1. A pre-trained language model learns a common language representation from a massive corpus. When training downstream tasks, model parameters are no longer randomly initialized. Instead, they are initialized using parameters obtained from upstream pre-training before training. Typical pre-trained language models include ELMO (embeddings from Language Models), GPT (Generative Pre-Training), and BERT (Bidirectional Encoder Representations from Transformer).
[0089] 2. Food safety means that food is non-toxic and harmless, meets the necessary nutritional requirements, and does not cause any acute, subacute or chronic harm to human health.
[0090] 3. Natural Language Processing (NLP) is an important field in computer science and artificial intelligence. It studies various theories and methods that enable effective communication between humans and computers using natural language.
[0091] 4. The BERT model, which uses the Transformer encoder architecture, learns universal language representations from massive amounts of data by designing two proxy tasks. The downstream model then fine-tunes specific tasks. It has achieved breakthroughs in 11 natural language processing tasks, including text entailment recognition, text matching, and natural language question reasoning.
[0092] 5. Risk Classification: Food safety issues are classified and stratified based on laws and regulations, industry practices, and potential risks to consumers (including physical, financial, and psychological exposure). Risk severity is categorized into levels P1 to P3. Based on food safety types, attribution analysis results are divided into five categories: medical treatment for illness, foreign matter, spoilage, expiration, and undercooked food.
[0093] P1: After consuming the merchant's product, users suffer serious physical damage, such as shock, coma, etc., and need emergency treatment or hospitalization; or a collective illness and medical treatment incident involving 3 to 10 people occurs (medical certificate issued by the hospital)
[0094] P1 foreign matter: rats, medical needles, family planning products, condoms, razor blades, sanitary napkins (used), Band-Aids (used), medical cotton balls (used), broken glass, human teeth (not suspected), sharp nails (sharp iron nails / sharp screws), saliva (in food), sputum (in food), needles, earrings, malignant infectious sources (sperm, human blood / human blood), frogs, earthworms, geckos, lizards and other foreign matter in food. P2 foreign matter: seeking medical treatment for illness: after consuming the merchant's products, users experience general harmful symptoms, such as diarrhea, abdominal pain, nausea, vomiting, fever, etc., and can recover after simple treatment in the outpatient clinic (medical certificate or other relevant certificate issued by the hospital)
[0095] P2 foreign matter: fingernails, human pubic hair, sanitary napkins (unused), cigarette butts, lighters, metal bottle caps, flies, bees, sharp objects (sharp plastic, sharp stones, sharp wire, sharp metal sheets, sharp steel wire, sharp ceramics, sharp tiles, sharp toothpicks / bamboo sticks, Band-Aids (unused), iron chains / iron rings, batteries, saliva (outside of food), spit (outside of food), cockroaches, ants (more than 10), maggots, maggots, mouse droppings, human teeth (suspected), teeth (animal), clips, non-sharp nails (non-sharp nails / non-sharp screws), nuts, springs, water pipes, wire, sewer plugs, metal sheets (containing mercury), wire mesh, ceramic pieces, centipedes, spiders, fish lice, fish bones (not fish food), wood splinters, cigarette ash, fruit flies, houseflies, etc.
[0096] P2 level spoilage: The food in the meal shows signs of corruption and spoilage, and the spoilage is clearly visible to the naked eye.
[0097] P2 Expired: The food in the complaint has been confirmed to have expired / the product has no production date or expiration date information. P3 Illness-Causing Medical Treatment: After consuming the merchant's product, the user experiences mild discomfort, such as fatigue, loss of appetite, etc., and no medical treatment is required or the user has recovered on their own without medical treatment.
[0098] P3 foreign matter: Cabbage worms, caterpillars, black rice worms, rice worms, less than 10 ants, flying insects, moths, mosquitoes, ladybugs, bean worms (hard-shelled insects), detached chicken and duck feathers, animal hair, eyelashes, other human hair (not private parts), cotton thread, yarn, plastic rope, rubber band, hemp rope, steel wool fragments, plastic brush bristles, animal and plant brush bristles, loofah fiber fragments, dishwashing sponge fragments, plastic tape, plastic packaging bag fragments, paper fragments, trademark fragments, and labels. Debris (excluding food items), plastic bottle caps, plastic foam, coal slag, coal, stones (non-sharp), staples, pen caps, rags, soap, toothpicks / bamboo sticks (non-sharp), cotton swabs, cotton balls, suspected used tableware, other kitchen utensils, rings, centipedes, menus, suspected cockroach eggs, suspected cockroach feces, suspected cockroach legs, suspected fly legs, thread, string, plastic bags, duct tape, plastic tubing, sticky notes, snails, and other foreign objects;
[0099] P3 and deterioration: The feedback pictures show no visible deterioration after naked eye observation / fresh fruits and vegetables are visibly deteriorated
[0100] P3 level expired: The production date or shelf life information is partially missing or unclear and cannot be identified
[0101] P3 level: Undercooked food: Complaints about undercooked or undercooked food.
[0102] Existing technologies mainly include the following two methods for online food risk control:
[0103] 1. Manual grading: The advantage is that skilled human graders can accurately and flexibly identify and classify various types of information. However, manual grading is inefficient. Even highly skilled human grading takes 15-30 seconds, which is insufficient for the timeliness requirements of billions of data points per day.
[0104] 2. Experts have summarized some rules for food safety risk grading. These rules can be used to identify food safety risks such as foreign matter and expired food. Compared to manual grading, this can also help to quickly complete risk grading. However, rule-based systems cannot resolve the issue of Chinese semantics:
[0105] 1) The delivery problem cannot be distinguished from the problem of medical treatment. For example: If a patient is hospitalized and the takeaway food is not delivered, does the hospitalized patient have to pick it up?
[0106] 2) Confusing tone with seeking medical treatment for illness, for example: The takeout is so bad, it’s disgusting.
[0107] 3) The quality and taste cannot be distinguished, for example: moldy smell, plastic smell.
[0108] 4) Unable to recognize deformed expressions, for example, describing mouse droppings as mouse poop, rat droppings, and some symbols, etc., which will lead to a lot of misidentification and missed recognition.
[0109] 5) Unable to correctly identify keywords that serve as adjectives, for example: the amount of a fingernail.
[0110] The method, device, electronic device and computer-readable storage medium for online food risk control provided in this application are intended to solve the above technical problems in the prior art.
[0111] The following specific embodiments describe in detail the technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.
[0112] Figure 1 FIG. 1 is an application environment diagram of a method for online food risk control in an embodiment. Figure 1 , the method for online food risk control is applied to a food safety risk identification system. The food safety risk identification system includes a terminal 110 and a server 120. The terminal 110 and the server 120 are connected via a network. The terminal 110 can specifically be a desktop terminal or a mobile terminal, and the mobile terminal can specifically be at least one of a mobile phone, a tablet computer, a laptop computer, etc. The server 120 can be implemented as an independent server or a server cluster consisting of multiple servers. It can be understood that the terminal 110 or the server 120 can be used to independently perform the food safety risk identification provided in the embodiments of the present application.
[0113] Specifically, in the embodiment of the present application, a computer device (such as Figure 1 The terminal 110 or server 120 shown in the figure) obtains comment text and keyword text related to catering; inputs the comment text into a pre-trained risk identification model to obtain the highest food safety risk level and attribution analysis results of the comment text output by the risk identification model.
[0114] See Figure 2 , which exemplarily shows a flow chart of a method for online food risk control according to an embodiment of the present application. As shown in the figure, the method includes:
[0115] S101, obtaining comment text and keyword text;
[0116] The embodiment of the present application can obtain catering-related review text from preset content, which can include articles, videos, news, promotional information, applications, or products.
[0117] For example, suppose the content is a takeaway restaurant ordering page pushed to the user by the application. Figure 3 As shown in the figure, the left picture shows the content viewing entrance of the takeaway shop, through which the content viewing entrance enters the content display page shown in the right picture. The content display page displays the ordering page pushed to the user by the application.
[0118] A review is a user's subjective or objective description of a product displayed on the ordering page after ordering it. The review includes a user's comments on the food, which can be positive or negative.
[0119] For example, if Figure 4 As shown in the figure, the user comment area of the meal displays user comments about the meal. For example, the comments may be: "Is there glass shards in the chicken roll?", "Three people in a dormitory had diarrhea and stomachache after eating it", "The boss is a rat", etc.
[0120] It is understood that a computer device may store a content library. This content library includes a number of food-related content. After the content in this content library is pushed to a user, when the user consumes the content, the user's comments on the content are generated. The computer device can activate these comments.
[0121] The keyword text includes keywords corresponding to the various attribution analysis results for food safety. This embodiment of the application matches different keywords to different attribution analysis results. For example, the keywords for P1-level medical treatment are words such as shock and coma, which indicate serious physical damage and / or the need for emergency treatment or hospitalization. For details, please refer to the description of keywords at each level in the above embodiment and will not be repeated here.
[0122] S102: Input the comment text and keyword text into a pre-trained risk identification model to obtain the highest food safety risk level of the comment text and target attribution analysis results output by the risk identification model.
[0123] The embodiment of the present application obtains the highest risk level of food safety of the comment text and the attribution analysis result output by the risk identification model by inputting the comment text and the keyword text into a pre-trained risk identification model. The embodiment of the present application does not specifically limit the level of the definition of food safety risk, for example, it can be level 3. When the comment text involves only one risk level, then the risk level is the highest risk level of food safety of the comment text. When the comment text involves multiple risk levels, the highest risk level is selected. For example, "There are stones visible to the naked eye in the rice bowl, and I had diarrhea for three days after eating it", where "stones" belong to P3 level foreign matter, and "diarrhea" belongs to P2 level. Therefore, the highest risk level of this comment is P2 level.
[0124] The target attribution analysis result is the attribution analysis result that reflects the highest risk level in the comment text. For example, the comment text "I ate their lamb skewers and stayed in the hospital for three days" has a security risk level of P1, and the attribution analysis result is "Seek medical treatment." The comment text "There were visible stones in the rice bowl, and I had diarrhea for three days after eating it" has an attribution analysis result of "Seek medical treatment."
[0125] It should be understood that before executing step S102, a risk identification model can also be pre-trained. Specifically, the risk identification model can be trained in the following manner: First, a certain number of sample comment texts and keyword texts are collected, and the food safety risk level and attribution analysis results of each sample comment text are obtained. It can be understood that the attribution analysis results of the sample comment texts are the attribution analysis results reflecting the highest risk level in the sample comment texts. Then, based on the highest risk level and attribution analysis results of the sample comment texts, the initial model is trained to obtain the risk identification model. The initial model can be a single neural network model or a combination of multiple neural network models.
[0126] The online method for controlling food risks in the embodiment of the present application obtains comment text and keyword text, and inputs the comment text and keyword text into a pre-trained risk identification model to obtain the food safety risk level and target attribution analysis results of the comment text. Compared with the manual identification method of the existing technology, it not only greatly improves the recognition efficiency, but also can accurately identify the attribution analysis results, that is, the keywords in the comment text that reflect the highest risk level, laying the foundation for subsequent rapid early warning of high-risk food safety incidents, accurate protection of consumer food safety complaints, and accurate risk management of catering service providers.
[0127] Based on the above embodiments, as an optional embodiment, the risk identification model includes a grading model and an attribution model, wherein the grading model is used to obtain the food safety risk level of the review text, and the attribution model is used to obtain the attribution analysis results of the food safety of the review text. By setting up the two models, the identification results of food safety risks can be obtained in a targeted manner.
[0128] See Figure 5 In this embodiment of the present application, the review text is input into a pre-trained risk identification model to obtain the food safety risk level and attribution analysis results of the review text output by the risk identification model, including:
[0129] The comment text and the corresponding pinyin text are input into the grading model 210 to obtain the CLS vector output by the grading model and the highest risk level of food safety of the comment text; the comment text, CLS vector and preset keyword text are input into the attribution model 220 to obtain the target attribution analysis result of food safety of the comment text output by the attribution model.
[0130] Through research, the embodiments of the present application found that Internet vocabulary or typos often appear in actual review texts. For example, users may enter "zhenbuchu" or "zhenbucuo" for "really good", and users may output "haoziweiju" for "haoziweizhi". If only the text record of the review text is used for recognition, the "needle" in "zhenbuchu" is normally a P1-level foreign object, but in fact, the context does not describe a foreign object, but rather means that the dining experience is great. For example, the "mouse" in "haoziweiju" is a P1-level foreign object, but in fact, the context does not describe a foreign object either, but rather means that the boss hopes not to do anything crooked. Since users' typos and the deformation of Internet terms cannot be enumerated, although the characters are different, their pinyins are the same or basically the same, so this application determines the pinyin of each character in the review text to form a corresponding pinyin text, and inputs the review text and the pinyin text together as input into the grading model, which can reduce the negative impact of such expressions on the results.
[0131] CLS stands for classification, and a CLS vector can be understood as a vector used for downstream classification tasks. In this embodiment of the application, the CLS vector is used to classify the highest risk level of the review text. The classification model in this embodiment of the application not only outputs the food safety risk level but also outputs the intermediate CLS vector to the attribution model. Because the CLS vector is derived from the Chinese and pinyin of the review text, the CLS vector-integrated review text is more semantically accurate.
[0132] It is understandable that the embodiment of the present application can also pre-train to obtain a rating model. Specifically, the rating model can be trained in the following manner: first, a certain number of sample comment texts are collected, and the highest food safety risk level and the corresponding pinyin text of each sample comment text are obtained. Then, the initial model is trained based on the sample comment text, the corresponding pinyin text and the highest risk level. Specifically, the sample comment text and the corresponding pinyin text are used as training samples, and the food safety risk level of the sample comment text is used as a training label for training, thereby obtaining a rating model. The initial model can be a single neural network model or a combination of multiple neural network models. For example, the initial model can be a BERT model.
[0133] The attribution model of the embodiment of the present application can obtain attribution analysis results based on the attention mechanism. Specifically, for example, on the one hand, it can be by determining the word vector of the comment text, calculating the first attention weight based on the word vector and the keyword text, and on the other hand, calculating the second attention weight through the CLS vector output by the rating model and the keyword text. Attribution through the two attention weights can more accurately determine the attribution analysis results.
[0134] The risk identification model of the embodiment of the present application obtains the CLS vector output by the grading model and the highest risk level of food safety of the review text by inputting the review text and the corresponding pinyin text into the grading model; and inputs the review text, the CLS vector and the preset keyword text into the attribution model to obtain the target attribution analysis result of food safety of the review text output by the attribution model.
[0135] See Figure 6 , which exemplarily shows a structural diagram of the grading model of an embodiment of the present application. As shown in the figure, the grading model includes an input layer 310, a pre-trained language model 320, and a classification layer 330. First, the input of the input layer 310 is the comment text and the corresponding pinyin text. For example, "I started to vomit and have diarrhea after eating dumplings", the corresponding pinyin text is "wochi le jiao zi jiu kai shi shang tu xia xie", the comment text and the corresponding pinyin text are input into the input layer 310, and the first segmentation sequence output by the input layer 310 after character-level segmentation of the comment text and the second segmentation sequence output after character-level segmentation of the pinyin text are obtained.
[0136] Among them, character-level segmentation refers to dividing a continuous character sequence into multiple individual characters or character sequences. Specifically, the computer device can use a preset segmentation method to perform character-level segmentation processing on the comment text and the pinyin text to obtain multiple characters or character sequences, thereby obtaining the first word segmentation sequence and the second word segmentation sequence corresponding to the comment text and the pinyin text. Among them, the word segmentation sequence can include one or more than one word. The preset segmentation method can be a word segmentation method based on character matching, semantic understanding, or statistics, etc.
[0137] Taking the above comment text as an example, the first participle sequence may include "I", "eat", "finish", "dumpling", "son", "just", "start", "start", "up", "spit", "down" and "diarrhea", and the corresponding second participle sequence may include "wo", "chi", "wan", "jiao", "zi", "jiu", "kai", "shi", "shang", "tu", "xia" and "xie".
[0138] The first word segmentation sequence and the second word segmentation sequence are used as inputs of the pre-trained language model 320, and input into the pre-trained language model 320 to obtain the vector representation of each word segmentation in the comment text output by the pre-trained language model 320 after integrating the full-text semantic information. It can be understood that the full-text semantic information of the embodiment of the present application includes both the full-text semantic information of the comment text and the full-text voice information of the pinyin text.
[0139] The vector representation is further used as the input of the classification layer 330, wherein the classification layer 330 further includes a pooling layer 3301, an activation function layer 3302 and a fully connected layer 3303. The vector representation is input into the pooling layer to obtain the CLS vector output by the pooling layer, and the CLS vector is input into the activation function layer 3302. The semantic learning is enhanced by the preset activation function. The embodiment of the present application does not make any specific limitation on the activation function. For example, it can be a Sigmoid function, a hyperbolic tangent tanh function, a rectified linear unit (ReLU) function, etc.
[0140] Finally, the output result of the activation function layer 3302 is used as the input of the fully connected layer 3303, and the value is input to the fully connected layer 3303 for classification to obtain the highest risk level of the comment text.
[0141] It should be noted that the TextCNN model is relatively incapable of identifying keywords that hit multiple different levels simultaneously. For example, it would classify a case like "Is it hygienic: glass shards in the chicken roll, steel wool wrapped in the pork chop, and no problems with the hot dog yet, they're really trying to kill me???" as P3, but ignores that the foreign matter "glass shards" is classified as P1. According to the principle that when food safety incidents hit multiple keywords simultaneously, the highest risk level of each keyword is used to classify them. The correct classification should be P1.
[0142] For example, the TextCNN model is also inaccurate in identifying cases where multiple people are seeking medical treatment for an illness. For example, it will classify a sample such as "Three people in a dormitory have diarrhea and stomachache after eating" as P2 because it recognizes keywords such as "diarrhea." However, according to the principle that "three to ten people seeking medical treatment for an illness should be classified as P1," the correct classification should be P1.
[0143] The multi-head attention mechanism in the conventional BERT model can effectively address the aforementioned TextCNN issues. However, BERT struggles with distorted text that doesn't appear in the training examples. For example, BERT can correctly classify a normal sentence like "There was a black thing resembling rat droppings on the chicken nugget inside the burger, and it also had a very unappetizing odor" as P2. However, for a sentence like "The hygiene is questionable. Halfway through eating, I found something resembling rat 10!!," which doesn't explicitly mention the keyword "rat droppings," BERT will incorrectly classify it as P1 due to the recognition of rat. For another example, for a sentence like "It tastes good. But why did I find a stapler while eating? It bit my tooth?", BERT will be classified as P1 due to the recognition of the keyword "needle." However, because "staple" and "dingshuzhen" are homophones, the correct classification should be P3.
[0144] Based on the above embodiments, as an optional embodiment, the pre-trained language model in the embodiment of the present application is a BERT model. Specifically, see Figure 7 , which exemplarily shows a structural diagram of a pre-trained language model according to an embodiment of the present application. As shown in the figure, the pre-trained language model includes a first embedding layer 410, a second embedding layer 420 and a transformer layer 430. Specifically,
[0145] The first word segmentation sequence, that is, the word segmentation result of the comment text, is used as the input of the first embedding layer to obtain the word embedding vector, segment embedding vector and position embedding vector of the comment text output by the first embedding layer.
[0146] Among them, word embedding converts words represented in natural language into vectors or matrices that computers can understand. Segment embedding, the value of this vector is automatically learned during model training and is used to characterize the global semantic information of the text and integrate it with the semantic information of individual words. Position embedding, because the semantic information carried by words appearing at different positions in the text varies (for example, "I love you" and "You love me"), the BERT model attaches different vectors to distinguish words at different positions.
[0147] In addition to the three embedding vectors described above, the embodiment of the present application also adds a pinyin embedding vector. By inputting the second word segmentation sequence into the second embedding layer 420, the pinyin embedding vector of the comment text output by the second embedding layer 420 is obtained.
[0148] Specifically, for each word in the second word segmentation sequence, a corresponding unique identifier is determined from a preset dictionary, and the unique identifier is input into the BertModel class source code for compilation to obtain the pinyin embedding vector.
[0149] In an embodiment of the present application, goole_zh_pinyin_vocab.txt (the pinyin version of goole_zh_vocab.txt downloaded in advance) can be pre-loaded, and a dictionary can be constructed with pinyin as the key and a unique identifier as the value. The unique identifier can be an Arabic numeral. For example, the unique identifier of the first pinyin in goole_zh_pinyin_vocab.txt is set to 1, the unique identifier of the second pinyin is set to 2, and so on. In this way, for each word in the second word segmentation sequence, the corresponding unique identifier is obtained by looking up the key-value pair in the dictionary.
[0150] The grading model of the embodiment of the present application can learn the deep semantic information of the descriptive text. Compared with the classification based on keyword-based rule-making, it can well distinguish non-food safety incidents such as "noodles taste like earthworms and are very unpalatable." The pre-training model based on the transformer structure and the use of the self-attention mechanism can well capture contextual description information. For example, it can accurately locate the following situation: "I had diarrhea after eating and then received an IV drip at a small clinic. There was no invoice or anything. There was hair in it. It was very uncomfortable and disgusting. I want to protect the rights of consumers." P2, while other deep learning models, because they cannot capture long-range dependencies, will grade the foreign body "hair" to P3.
[0151] Furthermore, the pinyin added in the embedding layer in the embodiments of the present application can enhance the recognition ability for words that are homophonic with the keywords. For example, in the sentence "Even if the food has been searched, how can I still eat it?", since "searched" is homophonic with the keyword "spoiled" related to food deterioration, after adding pinyin, the model can accurately locate to p3. Without pinyin, it will be classified as a p4 non-food safety incident. At the same time, the embedding of pinyin will improve the generalization performance of the model. For example, for the internet term "hao zi wei zhi", the pinyin of its variations "hao zi wei zhi", "hao zi wei zhi" is all "hao zi wei zhi".
[0152] When determining the attribution model in the embodiments of the present application, initially, a method based only on word2vec word vectors for attribution was adopted. However, through experiments, it was found that this scheme is not easily able to distinguish the primary and secondary keywords. For example, it will attribute a sentence like "It's spoiled, there's an odor, my stomach hurts, what's wrong with the merchant, I demand compensation" to the label "spoiled". But in fact, the semantics of this sentence involve P2 seeking medical treatment due to illness, so the correct attribution should be to the "seeking medical treatment" label. Another example is that due to the presence of the keyword "threw up", a statement like "Are these two dirty laoshushi? I'm going to throw up!" will be attributed to "seeking medical treatment". However, here "threw up" is just the user's description of a disgusting thought, not the "vomiting" expression related to seeking medical treatment. The correct attribution should be "foreign object".
[0153] The embodiments of the present application also use the BERT model for attribution. However, this method also has some problems. For example, it will attribute a statement like "I ate the original flavor sliced cake and had diarrhea for a whole day. It's obvious that the cake is expired. It's really something to use it for delivering food" to "expired". But since "expired" in the classification is limited to the expiration of products with packaging dates, rather than expressions like "expired meat" or "expired cake", there are also inaccuracy issues.
[0154] Based on the above embodiments, as an optional embodiment, please refer to Figure 8 , which exemplarily shows the flow schematic diagram of the target attribution analysis result output by the attribution model in the embodiments of the present application. As shown in the figure, the review text and the keyword text are respectively input into the word vector layer to obtain the first word vector of the review text and the second word vector of the keyword text output by the word vector layer.
[0155] Specifically, the word vector layer in the embodiments of the present application can be a word2vec model. This word2vec model can be trained using a preset corpus. The specific training method can be to first perform word segmentation on the corpus using jieba, and then train it using the gensim library.
[0156] In an embodiment of the present application, the first word vector and the second word vector are input into a first attention mechanism layer to obtain a first attention weight (attention1) of the comment text, and the CLS vector and the second word vector are input into a second attention mechanism layer to obtain a second attention weight (attention2) of the comment text.
[0157] The calculation of attention1 and attention2 is as follows:
[0158] The calculation method of attention1 is:
[0159] The first word vector of the comment text is represented by [batch_size, seq_len, emb_size (192)], where 192 indicates that the dimension of the first word vector is 192 dimensions.
[0160] The second word vector of the keyword text is represented as [175,192], where 175 indicates that there are 175 keywords in the keyword text.
[0161] The essence of the attention function can be described as a mapping from a query to a series of key-value pairs. Calculating attention is done in three steps:
[0162] The first step is to calculate the similarity between the query and each key to obtain the weight. Common similarity functions include dot product, concatenation, and perceptron.
[0163] The second step is to normalize these weights using a softmax function;
[0164] The third step is to perform a weighted summation of the weight and the corresponding key value to obtain the final attention. Currently in NLP research, key and value are often the same, that is, key = value.
[0165] In this embodiment of the present application, the query is [batch_size, seq_len, emb_size], the key and value are: [175, 192]. The subsequent calculation method is similar to attention2, except that emb_size does not need to be split again. For details, see the calculation method of attention2.
[0166] The calculation method of attention2 is:
[0167] CLS vector is represented as [batch_size, seq_len, emb_size(768)]
[0168] The second word vector of the keyword text is represented as [175,192]
[0169] So when calculating attention2, the query is [batch_size, seq_len, emb_size], and the key and value are [175, 192].
[0170] In this embodiment of the application, the emb_size in the query is split into 4 heads, so that the query is expressed as [batch_size, 4, seq_len, emb_size / 4]. In this way, after the key is transposed, the matmul operation can be used, and the sum is softmaxed to calculate the score. After obtaining the score, the score and value are matmuled, and finally the result is reshaped back to [batch_size, seq_len, emb_size].
[0171] That is to say, the embodiment of the present application adopts a collaborative attribution approach of word2vec and BERT (since the CLS vector is obtained based on the BERT model). The multi-head attention in the BERT model can capture the impact of the descriptive text on different rated keywords, and the W2V part can effectively supplement the areas that the multi-head attention has not noticed. Moreover, since the attribution model uses the embedding of the comment text as the query and the keyword text as the key and value to calculate the weight of the rated statement to the keyword text, by calculating the attention weight of the text to be classified to the rated keyword, compared with keyword attribution, it can solve the problems of users seeking medical treatment due to non-food safety incidents such as "It's too spicy, my stomach hurts" and "This cake is so hard that it ate my teeth".
[0172] Finally, by inputting the first attention weight and the second attention weight into the classification layer, the classification layer outputs the target attribution analysis result of the comment text.
[0173] On the basis of the above embodiments, the comment text may be preprocessed before word segmentation, and the preprocessing includes special symbol processing, English uppercase and lowercase conversion, and unification of traditional and simplified Chinese characters.
[0174] See Figure 9 , which exemplarily shows a flow chart of a method for online food risk control provided by another embodiment of the present application, as shown in the figure, including:
[0175] S201, displaying a comment editing interface, wherein the comment editing interface displays the comment text to be published;
[0176] S202: In response to a comment publishing operation for the comment text, display the published comment text, the highest food safety risk level of the comment text, and a target attribution analysis result.
[0177] The online method for controlling food risks in the embodiment of the present application displays a comment editing interface in which the comment text to be published is displayed; in response to a comment publishing operation for the comment text, the food safety risk level and target attribution analysis results of the comment text can be displayed. Compared with the existing technology, it can provide users with instant feedback on food safety issues reflected in the comments, laying the foundation for subsequent rapid early warning of high-risk food safety incidents, accurate protection of consumer food safety complaints, and accurate risk management of catering service providers.
[0178] Based on the above embodiments, as an optional embodiment, the comment text after publication, as well as the highest food safety risk level and target attribution analysis results of the comment text are displayed, which also includes:
[0179] Inputting the review text and preset keyword text into a pre-trained risk identification model to obtain the highest food safety risk level of the review text and target attribution analysis results output by the risk identification model;
[0180] The keyword text includes keywords corresponding to various attribution analysis results of food safety;
[0181] The risk identification model is trained using sample review texts and keyword texts related to catering as training samples, and the highest food safety risk level and attribution analysis results of the sample review texts as training labels.
[0182] Based on the above embodiments, as an optional embodiment, the risk identification model includes a rating model;
[0183] Inputting the review text into a pre-trained risk identification model to obtain the highest food safety risk level and attribution analysis result of the review text output by the risk identification model includes:
[0184] Inputting the review text and the corresponding pinyin text into the grading model to obtain the highest food safety risk level of the review text output by the grading model;
[0185] The grading model is trained based on the sample review text and the corresponding pinyin text as training samples, and the highest food safety risk level of the sample review text as a training label.
[0186] Based on the above embodiments, as an optional embodiment, the rating model further outputs a CLS vector; wherein the highest risk level is determined according to the CLS vector.
[0187] Based on the above embodiments, as an optional embodiment, the risk identification model further includes an attribution model;
[0188] Inputting the review text into a pre-trained risk identification model to obtain the highest food safety risk level of the review text and a target attribution analysis result output by the risk identification model includes:
[0189] Inputting the comment text, the CLS vector, and a preset keyword text into the attribution model to obtain a target attribution analysis result of the comment text output by the attribution model;
[0190] The attribution model is trained based on the sample comment text, keyword text and the CLS vector of the sample comment text output by the rating model as training samples, and the attribution analysis results of the sample comment text as training labels.
[0191] Based on the above embodiments, as an optional embodiment, the rating model includes an input layer, a pre-trained language model and a classification layer;
[0192] Inputting the review text and the corresponding pinyin text into the grading model to obtain the CLS vector output by the grading model and the highest food safety risk level of the review text, including:
[0193] Inputting the comment text and the corresponding pinyin text into the input layer, obtaining a first word segmentation sequence output by the input layer after character-level segmentation of the comment text and a second word segmentation sequence output by the input layer after character-level segmentation of the pinyin text;
[0194] Inputting the first segmentation sequence and the second segmentation sequence into the pre-trained language model to obtain a vector representation of each segmentation in the review text output by the pre-trained language model after integrating the semantic information of the full text;
[0195] The vector representation is input into the classification layer to obtain the CLS vector output by the classification layer after pooling, activation function and full connection processing, as well as the highest risk level of the comment text.
[0196] Based on the above embodiments, as an optional embodiment, the pre-trained language model is a BERT model, and the BERT model includes a first embedding layer, a second embedding layer, and a transformer layer;
[0197] Inputting the first word segmentation sequence and the second word segmentation sequence into the pre-trained language model to obtain the vector representation of the review text output by the pre-trained language model includes:
[0198] Input the first word segmentation sequence into the first embedding layer, and obtain the word embedding vector, segment embedding vector, and position embedding vector of the comment text output by the first embedding layer;
[0199] Inputting the second word segmentation sequence into the second embedding layer to obtain the pinyin embedding vector of the comment text output by the second embedding layer;
[0200] The word embedding word embedding vector, segment embedding segment embedding vector, position embeddings position embedding vector and pinyin embedding vector are input into the transformer layer to obtain the vector representation output by the transformer layer.
[0201] Based on the above embodiments, as an optional embodiment, inputting the second word segmentation sequence into the second embedding layer to obtain the pinyin embedding vector of the comment text output by the second embedding layer includes:
[0202] For each word in the second word segmentation sequence, determine the corresponding unique identifier from a preset dictionary, input the unique identifier into the BertModel class source code for compilation, and obtain the pinyin embedding vector;
[0203] The preset dictionary includes at least one word segment and a corresponding unique identifier.
[0204] Based on the above embodiments, as an optional embodiment, the attribution model includes a word vector layer, a first attention mechanism layer, a second attention mechanism layer, and a classification layer;
[0205] Inputting the comment text, the CLS vector, and the keyword text into the attribution model to obtain the food safety attribution analysis result of the comment text output by the attribution model includes:
[0206] Input the comment text and keyword text into the word vector layer respectively, and obtain the first word vector of the comment text and the second word vector of the keyword text output by the word vector layer;
[0207] Inputting the first word vector and the second word vector into a first attention mechanism layer to obtain a first attention weight of the comment text;
[0208] Inputting the CLS vector and the second word vector into the second attention mechanism layer to obtain the second attention weight of the comment text;
[0209] The first attention weight and the second attention weight are input into the classification layer, and the classification layer outputs the target attribution analysis result of the comment text.
[0210] Based on the above embodiments, as an optional embodiment, the method for online food risk control further includes:
[0211] Displaying a meal ordering interface, which includes food risk information of the ordering merchant;
[0212] The food risk information includes at least one of the following:
[0213] 1) The number of food safety incidents of each risk level corresponding to the ordering merchants within the preset time period.
[0214] For example, the embodiment of the present application can count all food safety incidents that occurred in the meal ordering merchant within six months according to the risk level. According to the above embodiment, the present application will determine the highest risk level involved in each comment, so the present application can count according to the highest risk level of each comment.
[0215] 2) The proportion of food safety incidents at food ordering merchants.
[0216] The embodiment of the present application calculates the number of orders with food safety incidents divided by the number of all vertices to obtain the proportion of food safety incidents occurring in the ordering merchant. Furthermore, the present application can count the proportion of food safety incidents at each risk level.
[0217] 3) Food safety rating of the merchant you order from.
[0218] The food safety rating of the embodiment of the present application can be obtained based on the number of food safety incidents. For example, when the number of food safety incidents in a period of time is less than 1, the food safety rating is level 1; when the number of food safety incidents is between 1 and 5, the food safety rating is level 2; when the number of food safety incidents is greater than 5, the food safety rating is level 3. The embodiment of the present application provides a server, such as Figure 10 As shown, the apparatus may include: a text acquisition module 101 and a risk identification module 102, specifically:
[0219] A text acquisition module 101 is used to acquire comment text and keyword text, wherein the keyword text includes keywords corresponding to various attribution analysis results of food safety;
[0220] The risk identification module 102 is configured to input the review text and keyword text into a pre-trained risk identification model, and obtain the highest food safety risk level of the review text and target attribution analysis results output by the risk identification model;
[0221] The risk identification model is trained using sample review texts and keyword texts related to catering as training samples, and the highest food safety risk level and attribution analysis results of the sample review texts as training labels.
[0222] The server provided by the embodiment of the present invention specifically executes the process of the above-mentioned method embodiment. For details, please refer to the content of the above-mentioned method embodiment for controlling food risks online on the server side, which will not be repeated here. The server provided by the embodiment of the present invention obtains the comment text and keyword text, and inputs the comment text and keyword text into a pre-trained risk identification model to obtain the food safety risk level and target attribution analysis results of the comment text. Compared with the manual identification method of the prior art, it not only greatly improves the recognition efficiency, but also can accurately identify the attribution analysis results, that is, the keywords in the comment text that reflect the highest risk level, laying the foundation for subsequent rapid early warning of high-risk food safety incidents, precise protection of consumer food safety complaints, and precise risk management of catering service providers.
[0223] The embodiment of the present application provides a terminal, such as Figure 11 As shown, the terminal may include: a text acquisition module 201 and a risk identification module 202, specifically:
[0224] An interface display module 201 is used to display a comment editing interface, in which the comment text to be published is displayed;
[0225] The analysis result display module 202 is used to respond to the comment publishing operation on the comment text and display the comment text after publishing, as well as the highest food safety risk level and target attribution analysis results of the comment text.
[0226] The terminal provided by the embodiment of the present invention specifically executes the process of the above-mentioned method embodiment. For details, please refer to the content of the above-mentioned method embodiment for controlling food risks online on the terminal side, which will not be repeated here. The terminal provided by the embodiment of the present invention displays a comment editing interface, in which the comment editing interface displays the comment text to be published; in response to the comment publishing operation for the comment text, the food safety risk level and target attribution analysis results of the comment text can be displayed. Compared with the existing technology, it can provide users with instant feedback on food safety issues reflected in the comments, laying the foundation for subsequent rapid early warning of high-risk food safety incidents, precise protection of consumer food safety complaints, and precise risk management of catering service providers.
[0227] An electronic device is provided in an embodiment of the present application, which includes: a memory and a processor; at least one program stored in the memory, which, when executed by the processor, can achieve the following compared to the prior art: by obtaining comment text and keyword text, and inputting the comment text and keyword text into a pre-trained risk identification model, the food safety risk level and target attribution analysis results of the comment text can be obtained. Compared with the manual identification method of the prior art, not only the recognition efficiency is greatly improved, but also the attribution analysis results, that is, the keywords in the comment text that reflect the highest risk level, can be accurately identified, laying the foundation for subsequent rapid early warning of high-risk food safety incidents, accurate protection of consumer food safety complaints, and accurate risk management of catering service providers.
[0228] In an alternative embodiment, an electronic device is provided, such as Figure 12 As shown, Figure 12 The electronic device 4000 shown includes: a processor 4001 and a memory 4003. The processor 4001 and the memory 4003 are connected, for example, via a bus 4002. Optionally, the electronic device 4000 may further include a transceiver 4004. It should be noted that in actual applications, the number of transceivers 4004 is not limited to one, and the structure of the electronic device 4000 does not constitute a limitation on the embodiments of the present application.
[0229] Processor 4001 may be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It may implement or execute the various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this application. Processor 4001 may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, and the like.
[0230] Bus 4002 may include a path for transmitting information between the above components. Bus 4002 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus. Bus 4002 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 12 Only one thick line is used in the diagram, but this does not mean that there is only one bus or one type of bus.
[0231] The memory 4003 may be a ROM (Read Only Memory) or other types of static storage devices that can store static information and instructions, a RAM (Random Access Memory) or other types of dynamic storage devices that can store information and instructions, or an EEPROM (Electrically Erasable Programmable Read Only Memory), a CD-ROM (Compact Disc Read Only Memory) or other optical disk storage, optical disk storage (including compact discs, laser discs, optical discs, digital versatile discs, Blu-ray discs, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited to these.
[0232] The memory 4003 is used to store application code for executing the solution of the present application, and the execution is controlled by the processor 4001. The processor 4001 is used to execute the application code stored in the memory 4003 to implement the content shown in the above method embodiment.
[0233] The embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon, which, when executed on a computer, enables the computer to execute the corresponding contents of the aforementioned method embodiment. Compared with the prior art, by obtaining comment text and keyword text, and inputting the comment text and keyword text into a pre-trained risk identification model, the food safety risk level and target attribution analysis results of the comment text can be obtained. Compared with the manual identification method of the prior art, it not only greatly improves the recognition efficiency, but also can accurately identify the attribution analysis results, that is, the keywords in the comment text that reflect the highest risk level, laying the foundation for subsequent rapid early warning of high-risk food safety incidents, precise protection of consumer food safety complaints, and precise risk management of catering service providers.
[0234] The embodiment of the present application provides a computer program, which includes computer instructions, and the computer instructions are stored in a computer-readable storage medium. When the processor of the computer device reads the computer instructions from the computer-readable storage medium, the processor executes the computer instructions, so that the computer device executes the content shown in the aforementioned method embodiment. Compared with the existing technology, by obtaining comment text and keyword text, and inputting the comment text and keyword text into a pre-trained risk identification model, the food safety risk level and target attribution analysis results of the comment text can be obtained. Compared with the manual identification method of the existing technology, it not only greatly improves the recognition efficiency, but also can accurately identify the attribution analysis results, that is, the keywords in the comment text that reflect the highest risk level, laying the foundation for subsequent rapid warning of high-risk food safety incidents, accurate protection of consumer food safety complaints, and accurate risk management of catering service providers.
[0235] It should be understood that although the steps in the flowcharts of the accompanying drawings are shown in sequence as indicated by the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some of the steps in the flowcharts of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a portion of the sub-steps or stages of other steps.
[0236] The above are only some of the embodiments of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present invention. These improvements and modifications should also be regarded as within the scope of protection of the present invention.
Claims
1. A method for controlling food risks online, characterized in that: include: Obtaining comment text and keyword text, wherein the keyword text includes keywords corresponding to various attribution analysis results related to food safety; Inputting the review text and keyword text into a pre-trained risk identification model to obtain the highest food safety risk level of the review text and a target attribution analysis result output by the risk identification model; The risk identification model is trained using sample review texts and keyword texts related to catering as training samples, and the highest food safety risk level and attribution analysis results of the sample review texts as training labels; The risk identification model includes a rating model and an attribution model; Inputting the review text into a pre-trained risk identification model to obtain the highest food safety risk level and attribution analysis result of the review text output by the risk identification model includes: Inputting the review text and the corresponding pinyin text into the grading model, obtaining the highest food safety risk level and CLS vector of the review text output by the grading model; the highest risk level is determined by classifying and learning the CLS vector after reinforcing the semantics using a preset activation function; Inputting the comment text, the CLS vector, and a preset keyword text into the attribution model to obtain a target attribution analysis result of the comment text output by the attribution model; The grading model is trained based on the sample review text and the corresponding pinyin text as training samples, and the highest food safety risk level of the sample review text as the training label; The attribution model is trained based on the sample comment text, keyword text and the CLS vector of the sample comment text output by the rating model as training samples, and the attribution analysis results of the sample comment text as training labels.
2. The method for online food risk control according to claim 1, characterized in that: The rating model includes an input layer, a pre-trained language model and a classification layer; Inputting the review text and the corresponding pinyin text into the grading model to obtain the CLS vector output by the grading model and the highest food safety risk level of the review text includes: Inputting the comment text and the corresponding pinyin text into the input layer, obtaining a first word segmentation sequence output by the input layer after character-level segmentation of the comment text and a second word segmentation sequence output by the input layer after character-level segmentation of the pinyin text; Inputting the first segmentation sequence and the second segmentation sequence into the pre-trained language model to obtain a vector representation of each segmentation in the review text output by the pre-trained language model after integrating the semantic information of the full text; The vector representation is input into the classification layer to obtain the CLS vector output by the classification layer after pooling, activation function and full connection processing, as well as the highest risk level of the comment text.
3. The method for online food risk control according to claim 2, characterized in that: The pre-trained language model is a BERT model, and the BERT model includes a first embedding layer, a second embedding layer, and a transformer layer; Inputting the first word segmentation sequence and the second word segmentation sequence into the pre-trained language model to obtain the vector representation of the review text output by the pre-trained language model includes: Input the first word segmentation sequence into the first embedding layer, and obtain the word embedding vector, segment embedding vector, and position embedding vector of the comment text output by the first embedding layer; Inputting the second word segmentation sequence into the second embedding layer to obtain the pinyin embedding vector of the comment text output by the second embedding layer; The word embedding word embedding vector, segment embedding segment embedding vector, position embeddings position embedding vector and pinyin embedding vector are input into the transformer layer to obtain the vector representation output by the transformer layer.
4. The method for online food risk control according to claim 3, characterized in that: Inputting the second word segmentation sequence into the second embedding layer to obtain the pinyin embedding vector of the comment text output by the second embedding layer includes: For each word in the second word segmentation sequence, determine the corresponding unique identifier from a preset dictionary, input the unique identifier into the BertModel class source code for compilation, and obtain the pinyin embedding vector; The preset dictionary includes at least one word segment and a corresponding unique identifier.
5. The method for online food risk control according to any one of claims 1 to 4, characterized in that: The attribution model includes a word vector layer, a first attention mechanism layer, a second attention mechanism layer, and a classification layer; Inputting the comment text, the CLS vector, and the keyword text into the attribution model to obtain the food safety attribution analysis result of the comment text output by the attribution model includes: Input the comment text and keyword text into the word vector layer respectively, and obtain the first word vector of the comment text and the second word vector of the keyword text output by the word vector layer; Inputting the first word vector and the second word vector into a first attention mechanism layer to obtain a first attention weight of the comment text; Inputting the CLS vector and the second word vector into the second attention mechanism layer to obtain the second attention weight of the comment text; The first attention weight and the second attention weight are input into the classification layer, and the classification layer outputs the target attribution analysis result of the comment text.
6. A method for controlling food risks online, characterized in that: include: Displaying a comment editing interface, wherein the comment editing interface displays the comment text to be published; In response to a comment publishing operation for the comment text, displaying the published comment text, as well as the highest food safety risk level and target attribution analysis results of the comment text; The display includes the comment text after publication, the highest food safety risk level of the comment text, and the target attribution analysis results, and also includes: Inputting the review text and preset keyword text into a pre-trained risk identification model to obtain the highest food safety risk level of the review text and target attribution analysis results output by the risk identification model; The keyword text includes keywords corresponding to various attribution analysis results of food safety; The risk identification model is trained using sample review texts and keyword texts related to catering as training samples, and the highest food safety risk level and attribution analysis results of the sample review texts as training labels; The risk identification model includes a rating model and an attribution model; Inputting the review text into a pre-trained risk identification model to obtain the highest food safety risk level and attribution analysis result of the review text output by the risk identification model includes: Inputting the review text and the corresponding pinyin text into the grading model, obtaining the highest food safety risk level and CLS vector of the review text output by the grading model; the highest risk level is determined by classifying and learning the CLS vector after reinforcing the semantics using a preset activation function; Inputting the comment text, the CLS vector, and a preset keyword text into the attribution model to obtain a target attribution analysis result of the comment text output by the attribution model; The grading model is trained based on the sample review text and the corresponding pinyin text as training samples, and the highest food safety risk level of the sample review text as a training label; The attribution model is trained based on the sample comment text, keyword text and the CLS vector of the sample comment text output by the rating model as training samples, and the attribution analysis results of the sample comment text as training labels.
7. The method according to claim 6, characterized in that Also includes: Displaying a meal ordering interface, which includes food risk information of the ordering merchant; The food risk information includes at least one of the following: The number of food safety incidents at each risk level for the ordering merchant within a preset time period; The proportion of food safety incidents occurring at the aforementioned ordering merchants; as well as The food safety rating of the ordering merchant.
8. A server, characterized in that: include: A text acquisition module, configured to acquire comment text and keyword text, wherein the keyword text includes keywords corresponding to various attribution analysis results related to food safety; A risk identification module is used to input the review text and keyword text into a pre-trained risk identification model to obtain the highest food safety risk level of the review text and the target attribution analysis result output by the risk identification model; The risk identification model is trained using sample review texts and keyword texts related to catering as training samples, and the highest food safety risk level and attribution analysis results of the sample review texts as training labels; The risk identification model includes a rating model and an attribution model; Inputting the review text into a pre-trained risk identification model to obtain the highest food safety risk level and attribution analysis result of the review text output by the risk identification model includes: Inputting the review text and the corresponding pinyin text into the grading model, obtaining the highest food safety risk level and CLS vector of the review text output by the grading model; the highest risk level is determined by classifying and learning the CLS vector after reinforcing the semantics using a preset activation function; Inputting the comment text, the CLS vector, and a preset keyword text into the attribution model to obtain a target attribution analysis result of the comment text output by the attribution model; The grading model is trained based on the sample review text and the corresponding pinyin text as training samples, and the highest food safety risk level of the sample review text as a training label; The attribution model is trained based on the sample comment text, keyword text and the CLS vector of the sample comment text output by the rating model as training samples, and the attribution analysis results of the sample comment text as training labels.
9. A terminal, characterized in that: include: An interface display module is used to display a comment editing interface, in which the comment text to be published is displayed; An analysis result display module, configured to, in response to a comment publishing operation on the comment text, display the comment text after publishing, as well as the highest food safety risk level and target attribution analysis results of the comment text; Risk identification models include rating models and attribution models; Input the review text into a pre-trained risk identification model to obtain the highest food safety risk level and attribution analysis results of the review text output by the risk identification model, including: Input the review text and the corresponding pinyin text into the grading model to obtain the highest food safety risk level and CLS vector of the review text output by the grading model; the highest risk level is determined based on the CLS vector Inputting the comment text, the CLS vector, and a preset keyword text into the attribution model to obtain a target attribution analysis result of the comment text output by the attribution model; The grading model is trained based on sample review texts and corresponding pinyin texts as training samples, and the highest food safety risk level of the sample review texts as training labels; The attribution model is trained based on the sample comment text, keyword text and the CLS vector of the sample comment text output by the rating model as training samples, and the attribution analysis results of the sample comment text as training labels.
10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the steps of the method for online food risk control according to any one of claims 1 to 7 are implemented.
11. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer instructions, and the computer instructions enable the computer to execute the steps of the method for online food risk control according to any one of claims 1 to 7.
Citation Information
Patent Citations
Store food quality information collection method and device and electronic equipment
CN111738541A
Text classification model training method, text classification method and equipment
CN112084337A
Attention-fused aspect-level user comment text sentiment analysis method and attention-fused aspect-level user comment text sentiment analysis system
CN112329474A
Content publishing method and device, electronic equipment and computer storage medium
CN112948629A
Pre-training model acquisition and application method and device, equipment, medium and product
CN114444691A