Lens.orgの特許Data活用(TOYOTA 1/n)
企業がその特許にどれ程力を入れているかを示す指標のひとつとしてファミリー数があります。Lens.orgはそのファミリー数を簡単に取得できます。
ユーザー登録だけすれば、50,000件の特許の基本的なDataをファミリー数(Simple family, Extended family)とともに出力できます。
例えばLens.orgで出力したTOYOTAの特許を分類し、以下のような最近特に出願件数の多い"Smart Facility and Vehicle Navigation Systems"の特許群(赤線)を見つけたとします。
いくつかの特許に目を通したくなりますが、その際にはファミリー数の多いものから目を通しておけば間違いはないと思います。
以下、具体例です。
0. 環境
1. Lens.orgからData出力
応募者で "Toyota Motor Co Ltd" を選択、国・管轄庁で "US" を選択し、ひとつのフォルダに出力しました。
出力したファイルをDataframeにします。
path = r"C:\Users\Documents\Patent\Company\lens" #保存フォルダ
import pandas as pd
import glob
files = glob.glob(f"{path}/*.csv")
df = pd.DataFrame()
for file in files:
df_a = pd.read_csv(file)
df = pd.concat([df, df_a])
文献数は 67,848件でした。
今回は要約文で分類するため、要約がないDataは削除します。
df = df.dropna(subset=['要約'])
df = df.reset_index()
2. 要約文をもとに分類
基本的には
Bertopicが便利なので、Bertopicを使用。
embeddingにはBAAI(北京智源人工智能研究院)のbge-large-en-v1.5を使用。
docs = df['要約'].values
from bertopic import BERTopic
from bertopic.representation import KeyBERTInspired, MaximalMarginalRelevance
main_representation_model = KeyBERTInspired()
aspect_representation_model = [KeyBERTInspired(top_n_words=30),
MaximalMarginalRelevance(diversity=.5)]
representation_model = {
"Main": main_representation_model,
"Aspect": aspect_representation_model
}
embedding_mode = 'BAAI/bge-large-en-v1.5'
topic_model = BERTopic(verbose=True, embedding_model=embedding_model,
min_topic_size = 30,
representation_model = representation_model
)
topics, ini_probs = topic_model.fit_transform(docs)
結果
topic_model.get_topic_info()
300件を超えるtopicに分類され、一見多すぎてビジーに感じるかもしれませんが、あとで適切なtopic名をつけることで案外大した数ではないことが実感できます。
3. Topic名
それぞれのTopicの名称をLLMに決めてもらいます。
modelは、最近様々なmodelの日本語性能を大きく向上させることで有名なHODACHIさんのHODACHI/Llama-3.1-8B-EZO-1.1-itを使用しました。
modelを設定
import transformers
import torch
model_id = "HODACHI/Llama-3.1-8B-EZO-1.1-it"
pipeline = transformers.pipeline(
"text-generation",
model=model_id,
model_kwargs={"torch_dtype": torch.bfloat16},
device_map="auto",
)
分類時に設定したそれぞれのtopicのkeywordsと代表文をもとにtopic名を考えてもらいます。
from tqdm import tqdm
topic_names = []
for i in tqdm(range(len(topic_model.get_topic_info()))):
# for i in tqdm(range(3)):
DOCUMENTS = []
for j in topic_model.get_topic_info()["Representative_Docs"][i]:
DOCUMENTS.append(j[:1000])
"\n".join(DOCUMENTS)
KEYWORDS = topic_model.get_topic_info()["Aspect"][i]
system_prompt = """
<s>[INST] <<SYS>>
You are a helpful, respectful and honest assistant for labeling topics.
<</SYS>>
"""
example_prompt = """
I have a topic that contains the following documents:
- Traditional diets in most cultures were primarily plant-based with a little meat on top, but with the rise of industrial style meat production and factory farming, meat has become a staple food.
- Meat, but especially beef, is the word food in terms of emissions.
- Eating meat doesn't make you a bad person, not eating meat doesn't make you a good one.
The topic is described by the following keywords: 'meat, beef, eat, eating, emissions, steak, food, health, processed, chicken'.
Based on the information about the topic above, please create a short label of this topic. Make sure you to only return the label and nothing more.
[/INST] Environmental impacts of eating meat
"""
main_prompt = f"""
[INST]
I have a topic that contains the following documents:
{DOCUMENTS}
The topic is described by the following keywords: '{KEYWORDS}'.
Based on the information about the topic above, please create a short label of this topic. Make sure you to only return the label and nothing more.
[/INST]
"""
prompt = example_prompt + main_prompt
messages = [
{"role": "system", "content": system_prompt},
{"role": "user", "content": prompt},
]
outputs = pipeline(
messages,
max_new_tokens=512,
)
idx = outputs[0]["generated_text"][-1]['content'].find("\n")
topic_name = outputs[0]["generated_text"][-1]['content'][:idx]
topic_names.append(topic_name)
print(topic_name)
命名
topic_model.set_topic_labels(topic_names)
4. 系統樹
それぞれのtopicの系統樹を作成し、わかりやすくします。
fig = topic_model.visualize_hierarchy(width=1300, color_threshold=0.98, custom_labels=True, hierarchical_topics=hierarchical_topics)
fig.show()
それなりにいい感じで命名されているようにみえます。
5. topicのtrend
各topicの過去の出願数の推移を確認します。
years_list = df['発行年'].unique()
years_list.sort()
chart_df = pd.DataFrame()
for year in years_list:
a = df['topics'][df['発行年']==year].value_counts()
a_df = pd.DataFrame.from_dict(a.to_dict(), orient="index", columns=[year])
chart_df = pd.concat([chart_df, a_df], axis=1)
過去全体で最も出願件数が多いtopicと、ここ数年で最も多いtopicをplotしてみました。
ハイブリッド車のドライブシステムに関する特許が過去最も多く、そのpeakが2015年ごろで今は低下傾向です。
2020年直前から急にスマートファシリティ・ナビシステムが急増しています。
スマートファシリティ・ナビシステムの特許の中でファミリーの大きいものを確認します。
family_size = df['シンプルファミリーサイズ'][xlist]
pat_abst = df['要約'][xlist].values
pat_year = df['発行年'][xlist].values
pat_no = df['表示キー'][xlist].values
df_a = pd.DataFrame()
df_a['シンプルファミリーサイズ'] = family_size
df_a['要約']= pat_abst
df_a['発行年']=pat_year
df_a['no'] = pat_no
df_a.rename(columns={0:'要約'})
df_a=df_a.sort_values(by='シンプルファミリーサイズ' ,ascending=False)
df_a.head()
2020年前後と最近の特許でもファイミリー数は20近く、結構力を入れていそうです。
それぞれの要約をLLMに咀嚼してもらいます。
for abst in pat_abst[:5]:
system_prompt = """
<s>[INST] <<SYS>>
あなたは誠実で優秀な日本人のアシスタントです。原則日本語で回答してください。.
<</SYS>>
"""
prompt = f"""
[INST]
次の文章はある特許の要約です。わかりやすく簡単に説明してください。:
{abst}
[/INST]
"""
messages = [
{"role": "system", "content": system_prompt},
{"role": "user", "content": prompt},
]
outputs = pipeline(
messages,
max_new_tokens=512,
)
output = outputs[0]["generated_text"][-1]['content']
print(output)
とても"スマート"感があります。
最近急増化しているtopicを抽出すると下記のようになりました。
やはりとても"スマート"感があります。
Woven Cityですね。
6. 参考
この記事が気に入ったらサポートをしてみませんか?