前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >NLP读人民日报

NLP读人民日报

原创
作者头像
beyondma
修改2021-11-08 09:23:08
4570
修改2021-11-08 09:23:08
举报
文章被收录于专栏:Rust学习专栏Rust学习专栏

由于我工作中用NLP功能比较多,因此我试用的方向是通过NLP来梳理报纸中的内容,我首先分析了一下权威报刊的链接构成,比如:

代码语言:javascript
复制
http://paper.people.com.cn/rmrb/html/2021-06/01/nw.D110000renmrb_20210601_2-07.htm
image.gif
image.gif

是由以下元素构成:

1.url前缀:http://paper.people.com.cn/rmrb/html/是固定的前缀:

2.月:/2021-06/

3.日:01/

4.content前缀:nw.D110000renmrb_

5.Content日期:20210601

6.Content序号:2

7.细分序号:-07

8.后缀:.htm

再分析一下返回的html文本中正文的关键字都带“enpcontent”,那么我们想读一段时间的报纸内容就完全可以枚举一段时间内的所有日期,然后通过url拼接的方式来获得所有报道正文的链接。具体代码如下:

代码语言:javascript
复制
#coding=utf-8
import datetime
import re
import http.client, urllib.parse
import http.client, urllib.parse
import random
USER_AGENTS = [
    "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; AcooBrowser; .NET CLR 1.1.4322; .NET CLR 2.0.50727)",
    "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Acoo Browser; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506)",
    "Mozilla/4.0 (compatible; MSIE 7.0; AOL 9.5; AOLBuild 4337.35; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)",
    "Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US)",
]
def get_demo(endfix):
    print(endfix)
    params = urllib.parse.urlencode({})
    headers = {'Referer': 'http://paper.people.com.cn',
               'User-Agent': random.choice(USER_AGENTS ),
               'Accept-Language': 'zh-CN,zh;q=0.9',
               }
    conn = http.client.HTTPConnection("paper.people.com.cn", timeout=10)
    conn.request("GET",endfix , params, headers)
    r1 = conn.getresponse()
    html = r1.read()
    data = html.decode('utf-8')
    result = re.findall("enpcontent" + '.*', data)
    if len(result)>1:
      print(result[1])
      return result[1]
    else:
        return  ""
def get_date_list(start,end):
    date_list= []
    date = datetime.datetime.strptime(start,'%Y-%m-%d')
    end = datetime.datetime.strptime(end,'%Y-%m-%d')
    while date <= end:
        date_list.append(date.strftime('%Y-%m-%d'))
        date = date + datetime.timedelta(1)
    return date_list
datelist=get_date_list("2021-06-01","2021-06-5")
for dateitem in datelist:
    datestr="".join(dateitem.split('-'))
    datesplit=dateitem.split('-')
    datePrefix=datesplit[0]+'-'+datesplit[1]+"/"+datesplit[2]
    for i in range(1,10):
        for j in range(1,20):
            content=get_demo("/rmrb/html/"+datePrefix+"/nw.D110000renmrb_"+datestr+'_'+str(i)+"-"+str(j).zfill(2)+".htm")
image.gif
image.gif

五大关键词-数字货币、普惠金融、便捷、服务、金融科技

获得正文文本之后,就可以通过文本关键词提取功能来提取关键词,具体代码如下:

首先安装SDK

代码语言:javascript
复制
pip install azure-ai-textanalytics==5.1.0
image.gif
image.gif

注:以下代码均需要填写自己的key和endpoint

代码语言:javascript
复制
key = "paste-your-key-here"
endpoint = "paste-your-endpoint-here"
from azure.ai.textanalytics import TextAnalyticsClient
from azure.core.credentials import AzureKeyCredential
# Authenticate the client using your key and endpoint
def authenticate_client():
    ta_credential = AzureKeyCredential(key)
    text_analytics_client = TextAnalyticsClient(
            endpoint=endpoint,
            credential=ta_credential)
    return text_analytics_client
client = authenticate_client()
def key_phrase_extraction_example(client):
    try:
        documents = ["我爱你中国"]
        response = client.extract_key_phrases(documents = documents)[0]
        if not response.is_error:
            print("\t关键词:")
            for phrase in response.key_phrases:
                print("\t\t", phrase)
        else:
            print(response.id, response.error)
    except Exception as err:
        print("Encountered exception. {}".format(err))
       
key_phrase_extraction_example(client)
image.gif
image.gif

输出如下:

关键词:

中国

由于笔者在银行工作因此选取有关银行方面的报道,将关键词提取出来做成词云如下:

image.gif
image.gif

从3月至今的报道9805篇的报道来看,与“银行”直接相关的报道共489篇,占比约为5%,标题与“银行”直接相关的报道20篇,占比0.2%,从这些报道中来看,出现频率最高的关键词是:双循环、数字货币、普惠金融、便捷、服务、金融科技,和银行直接相关的五大关键词为数字货币、普惠金融、便捷、服务、金融科技。

从关键词的情况来看,今年与之前相比最大的变化就是 “普惠金融”、“绿色金融”、以及“高质量服务”等方面渐渐成为新的热点。

报道脉落-年初数字货币,年中绿色金融,全年贯穿普惠

还可以根据时间与关键词数量的对应关系,利用Python生成动态条形图如下,

image.png
image.png
image.gif
image.gif

从中可以看到有关银行的总体发展趋势如下:

一、数字货币渐行渐近

5月26日的《数字人民币渐行渐近》是今年首次以银行服务为主角的报道。在5月的中国国际消费品博览会上多家商业银行推出数字人民币体验区,让参观者使用银行手机应用或数字人民币卡式钱包,正如标题所说,这也标志着数字人民币距离全面推广越来越近了。

6月16日的《雄安新区完成首笔“链上”数字人民币工资代发》,与7月18日的《数字人民币试点场景超一百三十二万个》正式宣告数字货币的应用场景已经基本发展成熟。而9月6日《数字人民币进一步助力普惠金融服务》更是与贯穿全年的普惠主题结合了起来。

二、“碳达峰”、“碳中和”目标使绿色金融渐成重点

从7月6日《绿色金融助力高质量发展》的报道开始,绿色金融逐渐登上银行业报道的C位。截至2020年末,中国本外币绿色贷款余额约12万亿元,存量规模居世界第一;绿色债券存量约8000亿元,居世界第二。绿色金融的快速发展,提升了金融业的适应性、竞争力和普惠性。为支持绿色低碳转型、推动经济高质量发展发挥了积极作用,也成为我国参与全球经济金融治理的重要领域和亮点之一。

9月7日的《深耕绿色金融发展沃土》报道,就把发展工行、农行、中行、建行的四大国有银行在绿色贷款方面发展的良好态势进行了全面的报道,通过上半年年报显示,四大国有银行绿色贷款余额突破万亿元,其中工行绿色贷款余额已突破2万亿元,这都是非常了不起的成就。

  • 全年贯穿的普惠金融主线

普惠金融也是今年的一条主线,其中第一篇以银行业为主角的报道是6月28日的《微众银行发挥数字科技优势 践行普惠金融使命》,微众银行利用自身的科技优势,将信贷资源全面向小微企业倾斜,截至2020年末,小微企业管理贷款规模超过1200亿元,约为2020年初的3倍,高于各项贷款平均增速,为支持小微企业复工复产作出了贡献。

哪家行银行获得的曝光度最高?

通过将文本进行摘要后的分析,示例代码如下:

代码语言:javascript
复制
key = "paste-your-key-here"
endpoint = "paste-your-endpoint-here"
from azure.ai.textanalytics import TextAnalyticsClient
from azure.core.credentials import AzureKeyCredential
# Authenticate the client using your key and endpoint
def authenticate_client():
    ta_credential = AzureKeyCredential(key)
    text_analytics_client = TextAnalyticsClient(
            endpoint=endpoint,
            credential=ta_credential)
    return text_analytics_client
client = authenticate_client()
# Example method for summarizing text
def sample_extractive_summarization(client):
    from azure.core.credentials import AzureKeyCredential
    from azure.ai.textanalytics import (
        TextAnalyticsClient,
        ExtractSummaryAction
    )
    document = [
        "The extractive summarization feature uses natural language processing techniques to locate key sentences in an unstructured text document. "
        "These sentences collectively convey the main idea of the document. This feature is provided as an API for developers. "
        "They can use it to build intelligent solutions based on the relevant information extracted to support various use cases. "
        "In the public preview, extractive summarization supports several languages. It is based on pretrained multilingual transformer models, part of our quest for holistic representations. "
        "It draws its strength from transfer learning across monolingual and harness the shared nature of languages to produce models of improved quality and efficiency. "
    ]
    poller = client.begin_analyze_actions(
        document,
        actions=[
            ExtractSummaryAction(MaxSentenceCount=4)
        ],
    )
    document_results = poller.result()
    for result in document_results:
        extract_summary_result = result[0]  # first document, first result
        if extract_summary_result.is_error:
            print("...Is an error with code '{}' and message '{}'".format(
                extract_summary_result.code, extract_summary_result.message
            ))
        else:
            print("Summary extracted: \n{}".format(
                " ".join([sentence.text for sentence in extract_summary_result.sentences]))
            )
sample_extractive_summarization(client)
image.gif
image.gif

从报道出现次数来看,工、农、中、建四大国有银行无疑是第一梯队,他们四家行出现的次数比第5名国开行的34次要多出一倍,而国开行、农发行与交行是第二梯队,他们在今年被报道的次数基本都在30次左右;邮储与招行则属于第三梯队被报道的次数介于10次与20次之间;其余各家银行被报道的次数均没有超过10次,具体统计表及统计饼状图如下:

银行

报道中出现次数

中行/中国银行

84

建行/建设银行

82

农行/农业银行

80

工行/工商银行

76

国开行/国家开发银行

34

农发行/农业发展银行

30

交行/交通银行

28

邮储银行/邮政储蓄银行

18

招行/招商银行

12

光大银行

8

浦发银行

8

进出口银行

6

微众银行

4

网商银行

2

中信银行

2

浙商银行

2

北京银行

2

而在下面评价程度方面,则又有另一番有意思的景像。

哪家行获得的评价最好?

通过微软的AZURE提供的情感分析结果来看,示例代码如下:

代码语言:javascript
复制
key = "paste-your-key-here"
endpoint = "paste-your-endpoint-here"
from azure.ai.textanalytics import TextAnalyticsClient
from azure.core.credentials import AzureKeyCredential
# Authenticate the client using your key and endpoint
def authenticate_client():
    ta_credential = AzureKeyCredential(key)
    text_analytics_client = TextAnalyticsClient(
            endpoint=endpoint,
            credential=ta_credential)
    return text_analytics_client
client = authenticate_client()
# Example function for detecting sentiment in text
def sentiment_analysis_example(client):
    documents = ["I had the best day of my life. I wish you were there with me."]
    response = client.analyze_sentiment(documents=documents)[0]
    print("Document Sentiment: {}".format(response.sentiment))
    print("Overall scores: positive={0:.2f}; neutral={1:.2f}; negative={2:.2f} \n".format(
        response.confidence_scores.positive,
        response.confidence_scores.neutral,
        response.confidence_scores.negative,
    ))
    for idx, sentence in enumerate(response.sentences):
        print("Sentence: {}".format(sentence.text))
        print("Sentence {} sentiment: {}".format(idx+1, sentence.sentiment))
        print("Sentence score:\nPositive={0:.2f}\nNeutral={1:.2f}\nNegative={2:.2f}\n".format(
            sentence.confidence_scores.positive,
            sentence.confidence_scores.neutral,
            sentence.confidence_scores.negative,
        ))
         
sentiment_analysis_example(client)
# Example method for detecting opinions in text
def sentiment_analysis_with_opinion_mining_example(client):
    documents = [
        "The food and service were unacceptable, but the concierge were nice"
    ]
    result = client.analyze_sentiment(documents, show_opinion_mining=True)
    doc_result = [doc for doc in result if not doc.is_error]
    positive_reviews = [doc for doc in doc_result if doc.sentiment == "positive"]
    negative_reviews = [doc for doc in doc_result if doc.sentiment == "negative"]
    positive_mined_opinions = []
    mixed_mined_opinions = []
    negative_mined_opinions = []
    for document in doc_result:
        print("Document Sentiment: {}".format(document.sentiment))
        print("Overall scores: positive={0:.2f}; neutral={1:.2f}; negative={2:.2f} \n".format(
            document.confidence_scores.positive,
            document.confidence_scores.neutral,
            document.confidence_scores.negative,
        ))
        for sentence in document.sentences:
            print("Sentence: {}".format(sentence.text))
            print("Sentence sentiment: {}".format(sentence.sentiment))
            print("Sentence score:\nPositive={0:.2f}\nNeutral={1:.2f}\nNegative={2:.2f}\n".format(
                sentence.confidence_scores.positive,
                sentence.confidence_scores.neutral,
                sentence.confidence_scores.negative,
            ))
            for mined_opinion in sentence.mined_opinions:
                target = mined_opinion.target
                print("......'{}' target '{}'".format(target.sentiment, target.text))
                print("......Target score:\n......Positive={0:.2f}\n......Negative={1:.2f}\n".format(
                    target.confidence_scores.positive,
                    target.confidence_scores.negative,
                ))
                for assessment in mined_opinion.assessments:
                    print("......'{}' assessment '{}'".format(assessment.sentiment, assessment.text))
                    print("......Assessment score:\n......Positive={0:.2f}\n......Negative={1:.2f}\n".format(
                        assessment.confidence_scores.positive,
                        assessment.confidence_scores.negative,
                    ))
            print("\n")
        print("\n")
         
sentiment_analysis_with_opinion_mining_example(client)
image.gif
image.gif

银行业整体的形象非常正面。其中正面评价程度最高的几篇报道梳理如下:

一、邮储银行为残障人士打造有温度的金融服务,评价最高的报道

《邮储银行牢记初心使命 服务国计民生》是一篇针对邮储北京香山支行为残障人士提供定制化金融服务的报道,也是截止目前所有有关银行业报道中,情感分析结果正面性结果得分最高的,笔者认为这也很可能是《人民日报》上对某一家银行评价最高的年度报道了。

每一位来到中国邮政储蓄银行北京香山支行的新员工,都要接受手语服务“六部曲”培训,以帮助残障群体无差别地享受基础金融服务,香山支行创新性地推出特色手语服务,用温暖服务让金融更有温度。这一服务,香山支行坚持了10年,这样的做法摘得年度最高评价应该没有悬念了。

二、建设银行的适老化改造,迎得掌声最多

《建设银行,适老服务交出温》报道了建行有关适老服务建设网点的情况,今年6月,建设银行在北京倾力打造安华支行营业部、长安支行营业部、齐园路支行、朝阳北路支行、菜市口南街支行、架松支行6家“适老服务示范网点”,并全部通过北京国家金融科技认证中心标准认证,成为全国首批“适老服务示范网点”。

这篇报道获得的评价也很高,同时网友讨论的热度较高,评价也很积极,堪称是迎得掌声最多的报道。 三、国开行助学贷款、邮储银行新农贷直通车、中国银行养老金融等报道也获得较高评价。

《助学贷款,助力学子成长成才》以国家开发银行为例报道了目前我国大学生助学贷款的政策情况;《邮储银行湖北省分行:金融赋能润“三农” 全面助力乡村振兴》介绍了邮储银行“新农贷款直通车”的运行情况;《中国银行苏州分行 推动“养老+金融”深度融合》报道了中行苏州分行尊老卡项目的进展。这些报道在情感分析的结果中也都获得比较高的正面得分。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 五大关键词-数字货币、普惠金融、便捷、服务、金融科技
  • 报道脉落-年初数字货币,年中绿色金融,全年贯穿普惠
  • 哪家行银行获得的曝光度最高?
  • 哪家行获得的评价最好?
相关产品与服务
区块链
云链聚未来,协同无边界。腾讯云区块链作为中国领先的区块链服务平台和技术提供商,致力于构建技术、数据、价值、产业互联互通的区块链基础设施,引领区块链底层技术及行业应用创新,助力传统产业转型升级,推动实体经济与数字经济深度融合。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档