diff --git a/src/assets/scripts/index.ts b/src/assets/scripts/index.ts index ea9709c..f9ed956 100644 --- a/src/assets/scripts/index.ts +++ b/src/assets/scripts/index.ts @@ -51,6 +51,15 @@ model(['Was in the city yesterday - didn’t notice anything strange'])`, [Snippets.restApi]: "python -m deeppavlov riseapi insults_xlm_roberta_base -di", }, + evergreenClassification: { + [Snippets.cli]: + "python -m deeppavlov interact evergreenqa_bert -di", + [Snippets.python]: `from deeppavlov import build_model +model = build_model('evergreenqa_bert', download=True, install=True) +model(['In what year was Pushkin born?'])`, + [Snippets.restApi]: + "python -m deeppavlov riseapi evergreenqa_bert -di", + }, intentClassification: { [Snippets.cli]: "python -m deeppavlov interact intents_distilbert_base_multi -di", diff --git a/src/components/BaseSkill/BaseSkill.tsx b/src/components/BaseSkill/BaseSkill.tsx index 125b8a8..2dd7717 100644 --- a/src/components/BaseSkill/BaseSkill.tsx +++ b/src/components/BaseSkill/BaseSkill.tsx @@ -169,6 +169,8 @@ class BaseSkill extends Component { return answers.map(this.renderQA) } else if (renderAnswer.type === "insult") { return answers.map(this.renderInsult) + } else if (renderAnswer.type === "evergreen") { + return answers.map(this.renderEvergreen) } else if (renderAnswer.type === "sentiment") { return answers.map(this.renderSentiment) } else if (renderAnswer.type === "emotion") { @@ -177,7 +179,7 @@ class BaseSkill extends Component { return answers.map(this.renderTopic) } else if (renderAnswer.type === "entitylinking") { return answers.map(this.renderEntityLinking) - } + } } renderEntityLinking = (mes: Answer, i: number) => { const rest = { ...mes } @@ -289,6 +291,26 @@ class BaseSkill extends Component { ) } + renderEvergreen = (mes: Answer, i: number) => { + const { colors } = this.props.renderAnswer! + const answer = mes.answer[0].toString().toUpperCase() + + return ( +
+

+ + {answer === "1" ? "EVERGREEN" : "NON_EVERGREEN"} + +

+

{mes.question}

+
+ ) + } renderTopic = (mes: Answer, i: number) => { const { colors } = this.props.renderAnswer! const answer = mes.answer[0].toString().toUpperCase() diff --git a/src/components/BaseSkill/index.ts b/src/components/BaseSkill/index.ts index d6cd9db..26776c0 100644 --- a/src/components/BaseSkill/index.ts +++ b/src/components/BaseSkill/index.ts @@ -38,6 +38,7 @@ interface RenderAnswer { | "ranking" | "intent" | "insult" + | "evergreen" | "sentiment" | "topic" // new - here and below | "textsentiment" diff --git a/src/components/Classes/Classes.tsx b/src/components/Classes/Classes.tsx index ee7d1b2..e42b07a 100644 --- a/src/components/Classes/Classes.tsx +++ b/src/components/Classes/Classes.tsx @@ -9,6 +9,7 @@ import { topicClasses, sentimentClasses, insultClasses, + evergreenClasses, emotionClasses, Classes as ClassesList, } from "utils/utils" @@ -36,6 +37,7 @@ export const Classes: FC = (props) => { [Links.textTopic]: topicClasses, [Links.textSentiment]: sentimentClasses, [Links.textToxic]: insultClasses, + [Links.textEvergreen]: evergreenClasses, [Links.textEmotion]: emotionClasses, } diff --git a/src/pages/TextClassification/EvergreenQA.tsx b/src/pages/TextClassification/EvergreenQA.tsx new file mode 100644 index 0000000..ae2aa46 --- /dev/null +++ b/src/pages/TextClassification/EvergreenQA.tsx @@ -0,0 +1,71 @@ +import axios from "axios" +import React from "react" +import skillWrapper, { BaseSkillProps } from "components/BaseSkill" +import { Res } from "lib/api" +import { scripts } from "assets/scripts" +import { evergreenClasses } from "utils/utils" + +interface Req { + question: string +} + +const config: BaseSkillProps = { + title: "EvergreenQA Classification", + desc: ( +

+ EvergreenQA classification is used to determine whether questions have answers that never change - "Evergreen", - + and therefore require no extra information to be provided to an LLM for answer generation, + or they have answers that typically change over time - "Non_Evergreen", - and thus an LLM should be provided + with specific information that might have changed over years or months. + To learn more on implementation read our{" "} + + documentation + + . +

+ ), + docker: "deeppavlov/evergreen_en", + inputs: [ + { + title: "Text", + type: "textarea", + name: "question", + }, + ], + examples: [ + { + question: "When was America discovered?", + }, + { + question: "Who is the current Formula 1 champion?", + }, + { + question: "Combien de jours y a-t-il dans une année?", + }, + { + question: "Combien de temps faut-il pour voyager en train de Moscou à Vladivostok ?", + }, + { + question: "В каком году было последнее солнечное затмение?", + }, + { + question: "В каком году был проведён первый чемпионат мира по футболу?", + }, + { + question: "Где находится самое высокое здание в мире?", + }, + ], + api: async (stateReq: Req) => { + const req = { + x: [stateReq.question], + } + return await axios.post("http://127.0.0.1:5025/model", req) + }, + renderAnswer: { type: "evergreen", colors: evergreenClasses }, + snippets: scripts.textClassification.evergreenClassification, +} + +const Evergreen = skillWrapper("evergreen") +export default function () { + return +} diff --git a/src/router/Router.tsx b/src/router/Router.tsx index 52453fb..49d61ae 100644 --- a/src/router/Router.tsx +++ b/src/router/Router.tsx @@ -13,6 +13,7 @@ import NER from "pages/TokenClassification/NER" import ODQA from "pages/QuestionAnswering/ODQA" import ReadingComprehension from "pages/QuestionAnswering/ReadingComprehension" +import EvergreenQA from "pages/TextClassification/EvergreenQA" // prettier-ignore export const Router = () => ( @@ -21,6 +22,7 @@ export const Router = () => ( + {/* */} diff --git a/src/router/Routes.ts b/src/router/Routes.ts index baaafc1..f2ef700 100644 --- a/src/router/Routes.ts +++ b/src/router/Routes.ts @@ -7,6 +7,7 @@ import Intent from "pages/TextClassification/Intent" import NER from "pages/TokenClassification/NER" import ODQA from "pages/QuestionAnswering/ODQA" import ReadingComprehension from "pages/QuestionAnswering/ReadingComprehension" +import EvergreenQA from "pages/TextClassification/EvergreenQA" // import EntityLinking from "pages/TokenClassification/EntityLinking" // import KnowledgeBaseQA from "pages/QuestionAnswering/KnowledgeBaseQA" // import { TextFewShot } from "pages/TextClassification/TextFewShot" @@ -22,6 +23,7 @@ export enum Links { textTopic = "text_topic", textSentiment = "text_sentiment", textToxic = "text_toxic", + textEvergreen = "text_evergreen", textEmotion = "text_emotion", textFewShot = "text_few_shot", tokenNer = "token_ner", @@ -67,6 +69,10 @@ export const routesForDemo: Routes = { { title: "Toxicity", link: Links.textToxic, component: Toxic }, + { title: "EvergreenQA", + link: Links.textEvergreen, + component: EvergreenQA + }, { title: "Emotion", link: Links.textEmotion, component: Emotion }, diff --git a/src/utils/utils.tsx b/src/utils/utils.tsx index 5f1130f..f86526b 100644 --- a/src/utils/utils.tsx +++ b/src/utils/utils.tsx @@ -45,6 +45,10 @@ const insultClasses = { INSULT: { color: colors.red }, NOT_INSULT: { color: colors.green }, } +const evergreenClasses = { + NON_EVERGREEN: { color: colors.red }, + EVERGREEN: { color: colors.green }, +} const sentimentClasses = { NEGATIVE: { color: colors.red }, POSITIVE: { color: colors.bottlegreen }, @@ -356,6 +360,7 @@ export { renderNerClasses, ontonotesClasses, insultClasses, + evergreenClasses, sentimentClasses, topicClasses, emotionClasses,