Watson使用指南(四)

个性化见解(Personality Insights)

简介

该服务使应用程序通过社交媒体,企业数据或是其他的数据信息获得个性化的见解。该服务利用语言学的分析方法,通过来自诸如邮件、短信、博客和论坛帖子中的数据,推断出一些个体固有的性格特征,包括“Big Five”(注:大五类性格特征分析,一种心理学上的人格划分系统),需求,价值。

通过对复杂社交媒体信息的潜在分析,该服务可以描述出一幅大致的反映用户性格特征的用户画像。基于这些结果,这个服务还可以推断出消费习惯,通过带有时间戳的JSON数据,可以获得消费的时间行为。

关于本服务描述的性格特征模型详见个性化模型

关于消费模型,详见消费偏好

认证

在bluemix上创建该服务实例,并且获得用户名和密码,具体参见详见Watson使用指南

方法

获得账户信息(Get profile)

为输入文本的作者生成一个个性化的账户。本服务可以获得的最大内容是20MB,可以分析阿拉伯语,英语,日语,或是西班牙语。

参数:

  • text (string型,最大20MB)

  • content_type (string型,text/plain(默认)适用纯文本、text/html适用网页、application/json适用JSON数据,使用html或是纯文本时徐添加对数据格式的描述“charset”,例如:content_type=text/plain;charset=utf-8)

  • content_language (string型, 支持语言ar(阿拉伯语)、en(默认,英语)、es(西班牙语)、ja(日语))

  • accept (string型,响应类型:application/json、text/csv)

  • 、accept_language(string型,响应语言:ar (阿拉伯)、de (德)、en (英, 默认)、es (西)、fr (法)、it (意)、ja (日)、ko (韩)、pt-br (巴西,葡萄牙)、zh-cn (简体中文)、zh-tw (繁体中文)

  • raw_scores (bool型, 在标准百分数上是否返回原始得分,设置为false只返回标准百分数)

  • consumption_preferences (bool型,是否返回消费偏好,设置为false,不返回)

  • csv_headers (bool型,是否返回一个csv响应)

profile(text, content_type='text/plain', content_language=None,
  accept='application/json', accept_language=None, raw_scores=False,
  consumption_preferences=False, csv_headers=False)


personality_insights = PersonalityInsightsV3(
  version='2016-10-20',
  username='{username}',
  password='{password}')

with open(join(dirname(__file__), './profile.json')) as profile_json:
  profile = personality_insights.profile(
    profile_json.read(), content_type='application/json',
    raw_scores=True, consumption_preferences=True)

print(json.dumps(profile, indent=2))

返回结果

参数:

  • word_count (int型,必须,输入文本中的单词数)

  • processed_language (string型,必须,处理文本语言)

  • personality (对象,必须,大五类人格特征的数组)

    • trait_id (string型,必须,唯一标识表明结果类型)

    • name (string型,必须,性格特征)

    • category (string型,必须,性格类型)

    • percentile (number型,必须,性格特征得分)

    • raw_scorce (number型, 原始得分)

    • children (对象,详细信息)

  • needs (对象,必须,需求信息的数组,数组详细内容同大五类)

  • values (对象,必须,价值信息的数组,详细内容同大五类)

  • behavior (对象,有时间信息的详细行为)

    • trait_id (string型,必须,唯一标识表明结果类型)

    • name (string型,必须,性格特征)

    • category (string型,必须,特征类型)

    • percentage (number型,必须,输入数据的时间百分比)

  • consumption_preferences (对象,消费偏好)

    • consumption_preference_category_id (string型,必须,类别唯一标识)

    • name (string型,必须,类别名)

    • consumption_preferences (对象,必须,消费偏好详细信息)

      • consumption_preference_id (string型,必须,唯一标识)

      • name(string型,偏好名称)

      • score (number型,偏好得分:0.0(不喜欢)、0.5(一般)、1.0(喜欢))

  • warnings (对象,必须,警告信息)

    • warning_id (string型,必须,唯一标识ID)

    • message (string型,必须,警告信息)

  • word_count_message (string型)

"word_count": 15223,
  "processed_language": "en",
  "personality": [
    {
      "trait_id": "big5_openness",
      "name": "Openness",
      "category": "personality",
      "percentile": 0.8011555009553,
      "raw_score": 0.77565404255038,
      "children": [
        {
          "trait_id": "facet_adventurousness",
          "name": "Adventurousness",
          "category": "personality",
          "percentile": 0.89755869047319,
          "raw_score": 0.54990704031219
        },
        . . .
      ]
    },
    {
      "trait_id": "big5_conscientiousness",
      "name": "Conscientiousness",
      "category": "personality",
      "percentile": 0.81001753184176,
      "raw_score": 0.66899984888815,
      "children": [
        {
          "trait_id": "facet_achievement_striving",
          "name": "Achievement striving",
          "category": "personality",
          "percentile": 0.84613299226628,
          "raw_score": 0.74240118454888
        },
        . . .
      ]
    },
    {
      "trait_id": "big5_extraversion",
      "name": "Extraversion",
      "category": "personality",
      "percentile": 0.64980796071382,
      "raw_score": 0.56817738781166,
      "children": [
        {
          "trait_id": "facet_activity_level",
          "name": "Activity level",
          "category": "personality",
          "percentile": 0.88220584913965,
          "raw_score": 0.60106995926143
        },
        . . .
      ]
    },
    {
      "trait_id": "big5_agreeableness",
      "name": "Agreeableness",
      "category": "personality",
      "percentile": 0.94786124793821,
      "raw_score": 0.80677815631809,
      "children": [
        {
          "trait_id": "facet_altruism",
          "name": "Altruism",
          "category": "personality",
          "percentile": 0.99241983824205,
          "raw_score": 0.79028406290747
        },
        . . .
      ]
    },
    {
      "trait_id": "big5_neuroticism",
      "name": "Emotional range",
      "category": "personality",
      "percentile": 0.5008224041628,
      "raw_score": 0.46748200007024,
      "children": [
        {
          "trait_id": "facet_anger",
          "name": "Fiery",
          "category": "personality",
          "percentile": 0.17640022058508,
          "raw_score": 0.48490315691802
        },
        . . .
      ]
    }
  ],
  "needs": [
    {
      "trait_id": "need_challenge",
      "name": "Challenge",
      "category": "needs",
      "percentile": 0.67362332054511,
      "raw_score": 0.75196348037675
    },
    {
      "trait_id": "need_closeness",
      "name": "Closeness",
      "category": "needs",
      "percentile": 0.83802834041813,
      "raw_score": 0.83714327329724
    },
    . . .
  ],
  "values": [
    {
      "trait_id": "value_conservation",
      "name": "Conservation",
      "category": "values",
      "percentile": 0.89268222856139,
      "raw_score": 0.72135308187423
    },
    {
      "trait_id": "value_openness_to_change",
      "name": "Openness to change",
      "category": "values",
      "percentile": 0.85759916388086,
      "raw_score": 0.82551308431323
    },
    . . .
  ],
  "behavior": [
    {
      "trait_id": "behavior_sunday",
      "name": "Sunday",
      "category": "behavior",
      "percentage": 0.21392532795156
    },
    {
      "trait_id": "behavior_monday",
      "name": "Monday",
      "category": "behavior",
      "percentage": 0.42583249243189
    },
    . . .
    {
      "trait_id": "behavior_0000",
      "name": "0:00 am",
      "category": "behavior",
      "percentage": 0.4561049445005
    },
    {
      "trait_id": "behavior_0100",
      "name": "1:00 am",
      "category": "behavior",
      "percentage": 0.12209889001009
    },
    . . .
  ],
  "consumption_preferences": [
    {
      "consumption_preference_category_id": "consumption_preferences_shopping",
      "name": "Purchasing Preferences",
      "consumption_preferences": [
        {
          "consumption_preference_id": "consumption_preferences_automobile_ownership_cost",
          "name": "Prefers automobile ownership cost",
          "score": 0
        },
        . . .
      ]
    },
    {
      "consumption_preference_category_id": "consumption_preferences_health_and_activity",
      "name": "Health & Activity Preferences",
      "consumption_preferences": [
        {
          "consumption_preference_id": "consumption_preferences_eat_out",
          "name": "Prefers to eat out",
          "score": 1
        },
        . . .
      ]
    },
    {
      "consumption_preference_category_id": "consumption_preferences_environmental_concern",
      "name": "Environmental Concern Preferences",
      "consumption_preferences": [
        {
          "consumption_preference_id": "consumption_preferences_concerned_environment",
          "name": "Likely to be concerned about the environment",
          "score": 0
        }
      ]
    },
    {
      "consumption_preference_category_id": "consumption_preferences_entrepreneurship",
      "name": "Entreprenuership Preferences",
      "consumption_preferences": [
        {
          "consumption_preference_id": "consumption_preferences_start_business",
          "name": "Likely to start a business in next few years",
          "score": 1
        }
      ]
    },
    {
      "consumption_preference_category_id": "consumption_preferences_movie",
      "name": "Movie Preferences",
      "consumption_preferences": [
        {
          "consumption_preference_id": "consumption_preferences_movie_romance",
          "name": "Likely to like romance movies",
          "score": 1
        },
        . . .
      ]
    },
    {
      "consumption_preference_category_id": "consumption_preferences_music",
      "name": "Music Preferences",
      "consumption_preferences": [
        {
          "consumption_preference_id": "consumption_preferences_music_rap",
          "name": "Likely to like rap music",
          "score": 1
        },
        . . .
      ]
    },
    {
      "consumption_preference_category_id": "consumption_preferences_reading",
      "name": "Reading Preferences",
      "consumption_preferences": [
        {
          "consumption_preference_id": "consumption_preferences_read_frequency",
          "name": "Reading frequency",
          "score": 0
        },
        . . .
      ]
    },
    {
      "consumption_preference_category_id": "consumption_preferences_volunteering",
      "name": "Volunteering Preferences",
      "consumption_preferences": [
        {
          "consumption_preference_id": "consumption_preferences_volunteer",
          "name": "Have volunteering experience",
          "score": 0
        }
      ]
    }
  ],
  "warnings": []
}

文档原文地址:http://www.ibm.com/watson/dev...

语调分析(Tone Analyzer)

简介

该服务使用语言学的分析方式检测情感语调,社交倾向和书面写作风格

认证

在bluemix上创建该服务实例,并且获得用户名和密码,具体参见详见Watson使用指南

import json
from watson_developer_cloud import ToneAnalyzerV3


tone_analyzer = ToneAnalyzerV3(
   username='YOUR SERVICE USERNAME',
   password='YOUR SERVICE PASSWORD',
   version='2016-05-19')

方法

语调分析(Analyzer tone)

分析一段文本的语调。语调包括社交态度,感情,语言。每一类都有衍生的更多内容。

参数:

  • text (query型,GET必须,待分析文档,至少三个单词)

  • body (body型,POST必须,JSON或纯文本,待分析文档)

  • Content-Type (header型,POST必须,待分析文档类型)

  • version (query型, 必须,版本号,当前最新:2016-05-19)

  • tone (query型,语调分类标签)

  • sentences (query型,过滤句子层次)

import json
from watson_developer_cloud import ToneAnalyzerV3


tone_analyzer = ToneAnalyzerV3(
   username='YOUR SERVICE USERNAME',
   password='YOUR SERVICE PASSWORD',
   version='2016-05-19 ')

print(json.dumps(tone_analyzer.tone(text='A word is dead when it is said, some say. Emily Dickinson'), indent=2))

返回结果

参数:

  • document_tone (全部文档的语调分析)

  • tone_categories(语调类别:感情,语言,社交态度)

  • tones (具体信息。感情:anger、disgust、fear、joy、sadness;语言:analytical、confident、tentative(试探性);社交态度:openness、conscientiousness(责任)、extraversion(外向)、agreeableness、emotion_range)

  • score (语调得分)

  • tone_id (语调唯一标识)

  • category_id (语调类别)

  • category_name (类别名)

  • sentences_tone (句子层次语调分析)

  • sentence_id (句子唯一编号)

  • text (正在分析的文本)

  • input_from (句子中第一个字母的序号)

  • input_to (句子中最后一个字母的序号)

{
  "document_tone": {
    "tone_categories": [
      {
        "tones": [
          {
            "score": 0.25482,
            "tone_id": "anger",
            "tone_name": "Anger"
          },
          {
            "score": 0.345816,
            "tone_id": "disgust",
            "tone_name": "Disgust"
          },
          {
            "score": 0.121116,
            "tone_id": "fear",
            "tone_name": "Fear"
          },
          {
            "score": 0.078903,
            "tone_id": "joy",
            "tone_name": "Joy"
          },
          {
            "score": 0.199345,
            "tone_id": "sadness",
            "tone_name": "Sadness"
          }
        ],
        "category_id": "emotion_tone",
        "category_name": "Emotion Tone"
      },
      {
        "tones": [
          {
            "score": 0.999,
            "tone_id": "analytical",
            "tone_name": "Analytical"
          },
          {
            "score": 0.999,
            "tone_id": "confident",
            "tone_name": "Confident"
          },
          {
            "score": 0.694,
            "tone_id": "tentative",
            "tone_name": "Tentative"
          }
        ],
        "category_id": "language_tone",
        "category_name": "Language Tone"
      },
      {
        "tones": [
          {
            "score": 0.271,
            "tone_id": "openness_big5",
            "tone_name": "Openness"
          },
          {
            "score": 0.11,
            "tone_id": "conscientiousness_big5",
            "tone_name": "Conscientiousness"
          },
          {
            "score": 0.844,
            "tone_id": "extraversion_big5",
            "tone_name": "Extraversion"
          },
          {
            "score": 0.257,
            "tone_id": "agreeableness_big5",
            "tone_name": "Agreeableness"
          },
          {
            "score": 0.497,
            "tone_id": "emotional_range_big5",
            "tone_name": "Emotional Range"
          }
        ],
        "category_id": "social_tone",
        "category_name": "Social Tone"
      }
    ]
  }
}

文档原文地址:http://www.ibm.com/watson/dev...

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值