Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
nostrbuzzsのしくみ
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Yoji Shidara
March 10, 2023
Technology
650
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
nostrbuzzsのしくみ
Yoji Shidara
March 10, 2023
More Decks by Yoji Shidara
See All by Yoji Shidara
Searchnos & Search on Nostr
dara
0
380
searchnos について
dara
0
490
How nostrbuzzs works
dara
0
180
About searchnos
dara
0
180
HOME, GOPATH and me
dara
3
1.7k
The First Step for Building Groonga Bindings with Golang
dara
6
1.5k
まほうのひととき - The Magic Hour
dara
7
1k
JDK CHRONICLE
dara
2
8.9k
Timelapse Introduction
dara
1
710
Other Decks in Technology
See All in Technology
企画を Software Factory-ready にする——開発が高速になったとき、PdMの仕事はどう変わったか
yachibit
1
270
構造で守らせる データ・法務・セキュリティ・開発チームとつくる AI時代のデータガバナンスとデータ基盤のリアル
legalontechnologies
PRO
1
520
Codex を使った障害対応机上演習の実際
orgachem
PRO
0
360
自宅サーバと脆弱性
masakiokuda
1
110
DevelopersIO2026 -バックアップは“消されないこと”が9割-
yoshida0129
0
410
国際カードブランドルール変更に伴うクレジットカード決済取引仕様変更について
k1style
0
240
野良MCPサーバーを排除せよ!MCPサーバーのガバナンス
yukiogawa
1
240
Metadata - Section 2: Simple Metadata & Meta Tags
mohab1
0
140
Kiro Crewで「みのるん式」仕事術やってみた
minorun365
PRO
3
1.1k
演劇と私とスクラム
chinmo
0
160
AWSDirectConnectの構築の進め方を整理してみた
masa_my
1
200
Let's Change Our World—Again
snoozer05
PRO
6
680
Featured
See All Featured
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
ラッコキーワード サービス紹介資料
rakko
4
5.5M
The SEO Collaboration Effect
kristinabergwall1
1
600
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
410
Game over? The fight for quality and originality in the time of robots
wayneb77
1
310
Darren the Foodie - Storyboard
khoart
PRO
4
4k
Side Projects
sachag
456
43k
Information Architects: The Missing Link in Design Systems
soysaucechin
1
1.2k
The Curious Case for Waylosing
cassininazir
1
580
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3.1k
How to Think Like a Performance Engineer
csswizardry
28
2.9k
Ten Tips & Tricks for a 🌱 transition
stuffmc
1
270
Transcript
nostrbuzzs のしくみ npub1q7qyk7rvdga5qzmmyrvmlj29qd0n45snmfuhkrzsj4rk0sm4c4psvqwt9c 2023-03-10 Nostr 勉強会 #1
@darashi Twitter のイマを切り取るサービス buzztter.com ( 運用終了) の作者です。 nostr の イマを切り取るサービス
nostrbuzzs をつくりました。 (NEW! Nostr 村放送局をつくりました。)
nostrbuzzs https://nostrbuzzs.deno.dev/
全体の構成 deno deploy fly.io nostrverse kind:1 kind:1 recent notes phrase
frequency kind:38225 kind:38225 static assets nostrbuzzs.deno.dev indexer analyzer ElasticSearch nostr-rs-relay relay.damus.io nos.lol web-browser
Indexer deno deploy fly.io nostrverse kind:1 kind:1 recent notes phrase
frequency kind:38225 kind:38225 static assets nostrbuzzs.deno.dev indexer analyzer ElasticSearch nostr-rs-relay relay.damus.io nos.lol web-browser リレーに接続して kind1 を収集します。 content の言語推定を行い、日本語と推定されたものだけ Elasticsearch にイン デックスします。 言語推定には https://github.com/pemistahl/lingua-go をつかっています。
Elasticsearch deno deploy fly.io nostrverse kind:1 kind:1 recent notes phrase
frequency kind:38225 kind:38225 static assets nostrbuzzs.deno.dev indexer analyzer ElasticSearch nostr-rs-relay relay.damus.io nos.lol web-browser https://www.elastic.co/ をそのまま使っています。 Indexer から送られたデータを保持します。 Analyzer が分析するために必要な情報を提供します。 解析のため、形態素等でトークナイズせず N-gram でインデックスします。
Analyzer deno deploy fly.io nostrverse kind:1 kind:1 recent notes phrase
frequency kind:38225 kind:38225 static assets nostrbuzzs.deno.dev indexer analyzer ElasticSearch nostr-rs-relay relay.damus.io nos.lol web-browser Elasticsearch からデータをとって buzzphrases を求めます。 解析結果を Relay に Parameterized Replaceable Events (NIP-33) で送ります。
Web UI deno deploy fly.io nostrverse kind:1 kind:1 recent notes
phrase frequency kind:38225 kind:38225 static assets nostrbuzzs.deno.dev indexer analyzer ElasticSearch nostr-rs-relay relay.damus.io nos.lol web-browser いわゆる SPA です。 Fresh https://fresh.deno.dev/ で書きました。 当初は API サーバも実装していたので deno deploy に置いてありますが、静的な サイトです。
Analyzer の処理について、もうすこし詳しく
Analyzer 1/2 -- 頻出フレーズ抽出 1. Elasticsearch から直近2 時間分の note を取得する。
2. SimHash [1] ( 実装は https://crates.io/crates/simhash) を用いて note 間の類似性を 計算し、類似度の高い note は 1 つを残して削除する。 3. Sudachi で形態素に分解する。 4. PrefixSpan [2] ( 自前実装) を用いて、頻出フレーズを求める。 [1] Charikar, Moses S. "Similarity estimation techniques from rounding algorithms." Proceedings of the thiry-fourth annual ACM symposium on Theory of computing. 2002. [2] Han, Jiawei, et al. "Prefixspan: Mining sequential patterns efficiently by prefix- projected pattern growth." Proceedings of the 17th international conference on data engineering. IEEE, 2001.
Analyzer 2/2 -- スコア計算 5. 頻出フレーズの正規化(大文字小文字、NFKC )を行い、その結果が同一になるフ レーズ群の出現をまとめる。出現頻度が最大の表記を代表として採用する。 6. あるフレーズについて、同一
pubkey で複数の言及が有る場合は、最新の note に 代表させる。 7. 解析開始時刻とフレーズの出現時刻の差をみて、直近の出現が高い重みを持つよ うに重み付けする(ついでに解析窓の過去側の端がなめらかになるようにす る)。 8. Elasticsearch に問い合わせて、過去のフレーズの出現数を求め、直近の出現が多 く、過去の出現が少ないフレーズに高いスコアを与える。 9. 解析結果を relay に送信する。
Nostr 的おもしろポイント NIP-33 をつかった解析結果の受け渡し https://github.com/nostr-protocol/nips/blob/master/33.md
具体例 解析結果を JSON で content に入れます。 kind は 38225 で
buzz-phrases:jp というタグをつけています。 自前のリレーに送っています。 ❯ echo '["REQ", "_", {"kinds": [38225] }]' | nostcat --stream wss://example.com | jq . [ "EVENT", "_", { "content": "{\"phrases\":[{\"text\":\"bluesky といえば\"}, ... 中略... ,{\"text\":\"Windows100\"}],\"created_at\":\"2023-02-26T08:36:14.559572950+00:00\",\"language\":\"ja\"}", "created_at": 1677400574, "id": "789cdedc73c7472428c40a39ada18177fa44a1996c30783f0ec0b194ca676cb8", "kind": 38225, "pubkey": "fe295340106bb7b8f5b08f8b7c22000862abc9731dbb86f2f141301e13b4d024", "sig": "f5c6aaf310cd0b6c631bdaf1f909563b1ebf7f45c5db8cced25ab3fced93fba6d8337a03277f23e2e58a1e7aaf1c94cf9996daa58d97a6e80bbde64829fda4f9", "tags": [ [ "d", "buzz-phrases:ja" ] ] } ]
この構成のいいところ ブラウザに解析結果を返すための API サーバが不要です。 この API サーバでは、 新たにつなぎに来たブラウザには、キャッシュしてある最新の結果を即時で返す Analyzer から新たな結果が来たら、接続中のブラウザ全部に通知する
という処理が必要です。単純だけど、ストレージが必要だったりしてちょっと面倒。 (初期バージョンはそういう実装になっていました) これが NIP-33 で解決します。
NIP-33: Parameterized Replaceable Events 「kind, pubkey, d タグが同じイベントが来たら、古いイベントを置き換える」 要するに、 Relay
は最新の 1 件だけ保持して返してくれる。 めっちゃ便利。 しかも複数のリレーに publish するだけで冗長構成を取れます。
応用例 誰でもバズフレーズを受け取って表示するサイトを作れます。 予告なく仕様が変わるかもしれませんが... もし、誰かが別の解析エンジンを実装したとして、それが同じプロトコルを実装 していれば、ユーザは切り替えて使用できるかもしれません。 たとえば pubkey で区別できます。 何を以て「トレンド」とするか。誰でもトレンドを発信できる。 人と人のコミュニケーションするためのイベントが主流だけど、Nostr
を介してサービ スとサービスがやりとりする世界観のも面白いのでは。
専用リレーの運用 nostr-rs-relay を使うとすぐできる。 config.toml の [authorization] セクショ ンの pubkey_whitelist に
Analyzer の pubkey を追加するだけ。 自サービス専用だと思うと気が楽 吊るしで使えるリアルタイム API サーバー
まとめ Nostr の buzz を解析して、表示するサービス nostrbuzzs をつくりました。 Relay を活用することで、 Nostr
っぽいアーキテクチャでつくりました。