1

Google Cloud Natural Language API を使用してツイートを分類/分類し、対象ユーザーに関係のない (天気に関連する) ツイートを除外しようとしています。AI ソリューションが短い量のテキストを分類するのは難しいに違いないことは理解できますが、少なくとも次のようなテキストを推測できると思います。

午前 6 時から 9 時にかけて、アーカンソー州北西部からアーカンソー州北部、オクラホマ州北部の一部に至るまで、0 度からマイナス 5 度の寒気が予想されます。#arwx #okwx

いくつかのツイートをテストしましたが、カテゴリ化されるのはごくわずかで、残りは結果が得られません (または、「カテゴリが見つかりません。より長いテキスト入力を試してください」という GUIを使用した場合)。

これが機能することを期待するのは無意味ですか?または、分類のしきい値を下げることはできますか? NLP ソリューションからの「知識に基づいた推測」は、フィルターをまったく使用しないよりも優れています。代替ソリューションはありますか (独自の NLP モデルのトレーニング以外)?

編集:明確にするために:

結局、ツイートを分類するために Google Cloud Platform Natural language API を使用しています。それをテストするために、私はGUIを使用しています(上記のリンク)。私が (GUI で) テストしたツイートのかなりの数が、GCP NLP から分類されていることがわかります。つまり、カテゴリは空です。

私が望む望ましい状態は、空の結果を提供するのではなく、GCP NLP がツイート テキストのカテゴリ推測を提供することです。NLP モデルは、信頼度が X% 未満の結果をすべて削除すると想定しています。そのしきい値を構成できるかどうかを知ることは興味深いでしょう.

ツイートの分類は以前に行われたにちがいないと思いますが、これを解決する他の方法があれば教えてください。

編集 2: ClassifyTweet-code:

async function classifyTweet(tweetText) {
   const language = require('@google-cloud/language');
   const client = new language.LanguageServiceClient({projectId, keyFilename});
   //const tweetText = "Some light snow dusted the ground this morning, adding to the intense snow fall of yesterday. Here at my Warwick station the numbers are in, New Snow 19.5cm and total depth 26.6cm. A very good snow event. Photos to be posted. #ONStorm #CANWarnON4464 #CoCoRaHSON525"
   const document = {
      content: tweetText,
      type: 'PLAIN_TEXT',
   };   
   const [classification] = await client.classifyText({document});
   
   console.log('Categories:');
   classification.categories.forEach(category => {
     console.log(`Name: ${category.name}, Confidence: ${category.confidence}`);
   });
   
   return classification.categories
}
4

1 に答える 1

1

私はクラウド自然言語の現状を掘り下げましたが、あなたの主要な質問に対する私の答えは、自然言語の現状ではテキストを分類することは不可能だということです。ただし、回避策は、入力からテキストを分析して得た出力に基づいてカテゴリを作成することです。

このためにカスタム モデルを使用しておらず、クラウドの自然言語が提供するオプションを使用しているだけであると考えてください。この問題に関する 1 つの暫定的なアプローチは次のとおりです。

まず、公式サンプルのコードを更新して、これについてもう少し説明する必要があります。

from google.cloud import language_v1 
from google.cloud.language_v1 import enums 


def sample_cloud_natural_language_text(text_content):
    """ 
    Args:
      text_content The text content to analyze. Must include at least 20 words.
    """

    client = language_v1.LanguageServiceClient()
    type_ = enums.Document.Type.PLAIN_TEXT

    language = "en"
    document = {"content": text_content, "type": type_, "language": language}


    print("=====CLASSIFY TEXT=====")
    response = client.classify_text(document)
    for category in response.categories:
        print(u"Category name: {}".format(category.name))
        print(u"Confidence: {}".format(category.confidence))


    print("=====ANALYZE TEXT=====")
    response = client.analyze_entities(document)
    for entity in response.entities:
        print(f">>>>> ENTITY {entity.name}")  
        print(u"Entity type: {}".format(enums.Entity.Type(entity.type).name))
        print(u"Salience score: {}".format(entity.salience))

        for metadata_name, metadata_value in entity.metadata.items():
            print(u"{}: {}".format(metadata_name, metadata_value))

        for mention in entity.mentions:
            print(u"Mention text: {}".format(mention.text.content))
            print(u"Mention type: {}".format(enums.EntityMention.Type(mention.type).name))


if __name__ == "__main__":
    #text_content = "That actor on TV makes movies in Hollywood and also stars in a variety of popular new TV shows."
    text_content="Wind chills of zero to -5 degrees are expected in Northwestern Arkansas into North-Central Arkansas extending into portions of northern Oklahoma during the 6-9am window"
    
    sample_cloud_natural_language_text(text_content)

出力

=====CLASSIFY TEXT=====
=====ANALYZE TEXT=====
>>>>> ENTITY Wind chills
Entity type: OTHER
Salience score: 0.46825599670410156
Mention text: Wind chills
Mention type: COMMON
>>>>> ENTITY degrees
Entity type: OTHER
Salience score: 0.16041776537895203
Mention text: degrees
Mention type: COMMON
>>>>> ENTITY Northwestern Arkansas
Entity type: ORGANIZATION
Salience score: 0.07702474296092987
mid: /m/02vvkn4
wikipedia_url: https://en.wikipedia.org/wiki/Northwest_Arkansas
Mention text: Northwestern Arkansas
Mention type: PROPER
>>>>> ENTITY North
Entity type: LOCATION
Salience score: 0.07702474296092987
Mention text: North
Mention type: PROPER
>>>>> ENTITY Arkansas
Entity type: LOCATION
Salience score: 0.07088913768529892
mid: /m/0vbk
wikipedia_url: https://en.wikipedia.org/wiki/Arkansas
Mention text: Arkansas
Mention type: PROPER
>>>>> ENTITY window
Entity type: OTHER
Salience score: 0.06348973512649536
Mention text: window
Mention type: COMMON
>>>>> ENTITY Oklahoma
Entity type: LOCATION
Salience score: 0.04747137427330017
wikipedia_url: https://en.wikipedia.org/wiki/Oklahoma
mid: /m/05mph
Mention text: Oklahoma
Mention type: PROPER
>>>>> ENTITY portions
Entity type: OTHER
Salience score: 0.03542650490999222
Mention text: portions
Mention type: COMMON
>>>>> ENTITY 6
Entity type: NUMBER
Salience score: 0.0
value: 6
Mention text: 6
Mention type: TYPE_UNKNOWN
>>>>> ENTITY 9
Entity type: NUMBER
Salience score: 0.0
value: 9
Mention text: 9
Mention type: TYPE_UNKNOWN
>>>>> ENTITY -5
Entity type: NUMBER
Salience score: 0.0
value: -5
Mention text: -5
Mention type: TYPE_UNKNOWN
>>>>> ENTITY zero
Entity type: NUMBER
Salience score: 0.0
value: 0
Mention text: zero
Mention type: TYPE_UNKNOWN

ご覧のとおり、classify textあまり役に立ちません (結果は空です)。それを開始するanalyze textと、いくつかの値を取得できます。それを使用して、カテゴリを作成または所有できます。トリック (そして大変な作業) は、分析するデータを設定するために使用できる各カテゴリ (私たちが作成したカテゴリ) に適合するキーワードのプールを作成することです。分類については、Google によって作成された利用可能なカテゴリの現在のリストをチェックして、カテゴリがどのように見えるべきかを知ることができます。

lower the bar現在のビルドでまだ実装されている機能はないと思いますが、機能としてグーグルにリクエストできるものです。

于 2022-01-28T17:41:06.450 に答える