• ↑ ͕Θ͔Δ͜ͱͰɺҎԼιϦϡʔγϣϯ͕࣮ݱͰ͖Δ • Ϩίϝϯυ, ҟৗݕग़, ྨ, ݕࡧ etc… • By learning the above, you can realize the following solution • Recommendation, outlier detection, classification problems, search etc... ͜ͷൃදͰֶΔ͜ͱɾͰ͖ΔΑ͏ʹͳΔ͜ͱ
consolidated account recommendation in Aug. 2023 • OpenAI ࣾͷ Embedding API Λ׆༻ Using OpenAI's Embedding API Ϋϥυ࿈݁ձܭʹՊϨίϝϯυػೳΛ࣮ ref: https://corp.moneyforward.com/news/release/service/ 20230804-mf-press-1/ We’ve Implemented a subject recommendation function in our application ※ ಛڐग़ئࡁΈ Pattent applied
parent company consolidated accounts that are semantically close to the individual company's accounts. ref: https://corp.moneyforward.com/news/release/service/ 20230804-mf-press-1/ Ϋϥυ࿈݁ձܭʹՊϨίϝϯυػೳΛ࣮ We’ve Implemented a subject recommendation function in our application
topic, we have had a lot of media coverage. • https://cloud.watch.impress.co.jp/docs/ news/1522209.html • https://it.impress.co.jp/articles/-/25192 • https://officenomikata.jp/news/15534/ • In total, about 8 articles... ଟ͘ͷϝσΟΞͰऔΓ্͖͛ͯ·ͨ͠ We have had a lot of media coverage.
record transactions of assets, etc. आํ Debit ିํ Credit Ո Rent expenses 50,000 ී௨༬ۚ Ordinary deposit 50,000 • ͜͜Ͱ͍͏ʮՈʯͱʮී௨༬ۚʯ͕ͦΕͧΕצఆՊ • The “Rent expenses" and “Ordinary deposit" here are the accounts respectively. ྫ: Ո 5 ສԁΛޱ࠲Ҿ͖མͱ͠Ͱࢧͬͨ߹ e.g. You paid 50,000 yen rent via direct debit. צఆՊ/࿈݁Պͱʁ What is an account/consolidated account?
is a process of taking the consolidated accounts and balance of the companies in the group and consolidating them into one account (consolidated account) of the parent company. צఆՊ/࿈݁Պͱʁ What is an account/consolidated account? ࢠձࣾA Company A ձࣾ Parent Company ී௨༬ۚ Ordinary Deposit Aۜߦ Bank A ݱۚٴͼ༬ۚ Cash & Deposit ࢠձࣾB Company B
ྫ: ʮʓʓۜߦʯͱʮී௨༬ۚʯɺʮݱۚٴͼ༬ۚʯͳͲ • ւ֎ࢠձ͕ࣾ͋Δ߹ʮʓʓ BankʯͳͲຊޠҎ֎ͷϞϊ͕དྷΔέʔε͋Δ • Many patterns cannot be absorbed by simple fuzzy search, edit distance, etc. • Ex: “XX bank” and “Ordinary deposit”, “Cash and deposits”, etc. • If there is an overseas subsidiary, there are cases where things other than Japanese are sent. • ҙຯͷۙ͞Ճຯͯ͠ɺݸࣾͷצఆՊʹҰ൪͍ۙ࿈݁ՊΛϨίϝϯυ ͢Δඞཁ͕͋Δɻ • It is necessary to recommend the consolidated accounts that are closest to the individual company's accounts, taking into account the proximity in meaning.
~ ઍ݅͋Δ͔Ͳ͏͔ • ֶशʹ͏ͳΒ࠷Ͱສ ~ ेສఔ΄͍͠ • At the moment there was still little data available for training. • At most, there are a few hundred ~ a thousand account conversion data • Training the model may require tens or hundreds of thousands of data. • ML Ϟσϧͷϝϯςίετਓࡐͷ֬อ͕ࠔ • ൃੜ࣌ʹରԠͰ͖Δਓͷ༻ҙ͔ΒɺϞσϧ࠶ֶशͳͲͷίετແࢹͰ͖ͳ͍ • Difficulty in securing maintenance costs and human resources for ML models • Preparing people who can respond to problems when they occur is difficult, and the cost of re-training models cannot be ignored.
into vectors. About Embedding / Word2Vec ”ݱ͓ۚΑͼ༬ۚ” [[-0.03455162],[-0.01306203], [ 0.01672893],…, [-0.00129271], [ 0.00694819],[-0.01055199]] • ϕΫτϧɺࢄදݱ͋Δ͍ຒΊࠐΈදݱͱݺΕΔ͜ͱ͋Δɻ • Sometimes called vector, distributed or embedded representation. ‘Cash and deposits’
ͳΔ߹ When "Cash" and "Liabilities" become [0.4, 0.8] and [-0.3, 0.9], respectively ුಈখͷྻʹͳΔ͜ͱͰɺ࠲ඪ·ͨϕΫτϧΛද͢͜ͱ͕Ͱ͖Δɻ It can represent coordinates or vectors by being a floating-point array. -0.5 0.5 1 0.5 1 ݱۚ ෛ࠴ Liabilities Cash 0
vectorize texts 1. ϕΫτϧಉ࢜ͷྨࣅΛଌΔ͜ͱ ͕Ͱ͖Δ Can calculate similarity between vectors Can perform numerical operations such as addition and subtraction against vectors
between vectors Can perform numerical operations such as addition and subtraction between vectors ← ࠓճ ͬͪ͜ This time we talk about this mainly. ϕΫτϧԽ͢ΔͱͰ͖Δ͜ͱ What you can implement when vectorize texts
two vectors, the similarity of vector orientation can be calculated • ίαΠϯྨࣅ͕Ұൠత • + Ͱਖ਼ͷ૬ؔɺ- Ͱෛͷ૬ؔ • Cosine similarity is generally used. • Plus means positive correction, negative means negative correction 1. ϕΫτϧಉ࢜ͷྨࣅΛଌΔ͜ͱ͕Ͱ͖Δ ݱۚ A ۜߦ Ո cos(‘ݱۚ’, ‘Aۜߦ’) = 0.85 cos(‘ݱۚ’, ‘Ո’) = 0.05 Rent expenses Rent expenses Cash Cash Cash Bank A Bank A Can calculate similarity between vectors
apply it for the below solution 1. ϕΫτϧಉ࢜ͷྨࣅΛଌΔ͜ͱ͕Ͱ͖Δ • Ϩίϝϯυʢྨࣅ͕ߴ͍ͷʣ- Recommendations (highly similarity) • ҟৗݕग़ (ྨࣅ͕͍ͷ) - Outlier detection (low similarity) • ྨʢྨࣅ͕͍ۙͷಉ࢜Ͱྨ͢Δʣ- Classification (Classify by its similarity) Can calculate similarity between vectors
apply it for the below solution 1. ϕΫτϧಉ࢜ͷྨࣅΛଌΔ͜ͱ͕Ͱ͖Δ • Ϩίϝϯυʢྨࣅ͕ߴ͍ͷʣ- Recommendations (highly similarity) • ҟৗݕग़ (ྨࣅ͕͍ͷ) - Outlier detection (low similarity) • ྨʢྨࣅ͕͍ۙͷಉ࢜Ͱྨ͢Δʣ- Classification (Classify by its similarity) Can calculate similarity between vectors
they can be added or subtracted (combined) if the number of dimensions matches. • ϕΫτϧಉ࢜Λ߹͢Δ͜ͱͰɺෳͷϕΫ τϧͷҙຯΛ࣋ͬͨ··ɺҰͭͷϕΫτϧʹ ͢Δ͜ͱ͕Ͱ͖Δ • Vectors can be combined into a single vector with the meaning of multiple vectors 2. ϕΫτϧಉ࢜ͷՃࢉɾݮࢉͳͲܭࢉ͕Ͱ͖ΔΑ͏ʹͳΔ IT ΦϨϯδ ۚ༥ܥ MoneyForward Can perform numerical operations such as addition and subtraction against vectors Orange Fintech
be implemented (IT will hit in the previous example). 2. ϕΫτϧಉ࢜ͷՃࢉɾݮࢉͳͲܭࢉ͕Ͱ͖ΔΑ͏ʹͳΔ Ref: https://www.google.com/ ͪΖΜݮࢉͰ͖ΔͷͰɺ Of course, we can also subtract them, Can perform numerical operations such as addition and subtraction against vectors MoneyForward -Fintech -Orange
Can perform numerical operations such as addition and subtraction against vectors 1. target_words ͷϕΫτϧΛܭࢉ͠ɺՃࢉ 2. ͦͯ͠ candidate_words ͷͦΕͧΕͱൺֱ 1. Compute and add vectors of target_words 2. Then compare the vector with each of the candidate_words ones
vector/distributed representation of text • 236݄ʹՁ֨վఆ͞Εɺada ϞσϧͰͦΕ·Ͱͷ 75% Φϑͷ $ 0.0001/ 1K token ʹͳͬͨ • Prices were revised in June 2023 to $ 0.0001/ 1K tokens, 75% off the previous price for the ada model. OpenAI ͷ Embedding API ʹ͍ͭͯ About OpenAI’s Embedding API
text-embedding-3-large ొ • In January 2012, an even less expensive model, text-embedding-3-small, became available at an additional 80% off! • A model text-embedding-3-large, which is more accurate than the previous model (ada), also became available • ߋʹ࣍ݩͷݮΛެࣜͰαϙʔτɻϕΫτϧܭࢉͷߴԽετϨʔδ༰ྔͷݮ͕ݟࠐΊΔ • Furthermore, the reduction of the number of dimensions is supported by the formula, which is expected to speed up vector calculations and reduce storage capacity. OpenAI ͷ Embedding API ʹ͍ͭͯ About OpenAI’s Embedding API
API is also available for an even lower cost. • Slow response (within 24 hours), but available at half price OpenAI ͷ Embedding API ʹ͍ͭͯ About OpenAI’s Embedding API • ϦΞϧλΠϜੑͷཁٻ͕͍ϞϊɺॳظσʔλߏஙͳͲʹద͍ͯ͠Δ • Suitable for low real-time objects, initial data construction, etc.
tokens, you can find out more about them below. • https://platform.openai.com/tokenizer • $1 ͏ͷʹ 100 ສ ~ 5,000 ສจࣈ͘Β͍ ͛Δඞཁ͕͋ΔͷͰɺίετͦ͜·Ͱ ؾʹͳΒͳ͍ • You need to send about 1 ~ 50 million letters to spend $1, so the cost is not much of a concern. OpenAI ͷ Embedding API ʹ͍ͭͯ About OpenAI’s Embedding API
Significantly improved accuracy in account recommendations compared to pre-reviewed model 0QFO"*UFYUFNCFEEJOHMBSHF Ґਖ਼ ҐἬਖ਼ ̍Ґਖ਼XJUIPVU&OHMJTI ҐἬਖ਼XJUIPVU&OHMJTI OpenAI ͷ Embedding API ʹ͍ͭͯ About OpenAI’s Embedding API
when the same text is sent, a vector cache mechanism can be created to reduce requests. • OpenAI ͷϨεϙϯε (ϦΫΤετʹΑΔ͕) ඵ͔͔Δͱ ͖͋ΔͷͰɺϨεϙϯελΠϜվળͷͨΊʹϕΫτϧ Ωϟογϡ͋ͬͨํ͕Α͍ • API’s response can take several seconds (depending on the request), so vector caching is recommended to improve response time. OpenAI ͷ Embedding API ʹ͍ͭͯ About OpenAI’s Embedding API
a general rate limit • Currently varies depending on Tier • ϦΫΤετʹΑΔ͕ɺΩϟογϡػߏ ͋Εֻ͔Δ͜ͱ͋·Γແ͍ • Depends on the number of requests, but with a cache mechanism, there is little to worry about. Embedding API ༻࣌ͷϝϞɾҙ Notes on using Embedding API
is apparently some kind of rate limit that is applied at the system-wide level. 1. ϨʔτϦϛοτ͕2छྨଘࡏ͢Δ • ଟ͍࣌ճʹ̍ճ͘Β͍ͷසͰ͜ͷϦϛοτʹ৮͢Δ • I encounter this rate limit error about once every few times at most.
OpenAI Exponential Backoff ΛਪɺPython ͍͔ͭ͘ϥΠϒϥϦͷαϯϓϧࡌ͍ͤͯΔɻ • Ref: https://platform.openai.com/docs/guides/ rate-limits/retrying-with-exponential-backoff • OpenAI also recommends Exponential Backoff and some Python sample code is also provided Rate Limit ͷରॲ๏ͱͯ͠ඍົʹࢥ͑Δ͕ɺಋೖҎ߱Ͱൃੜ݅΄΅θϩʹɻ Although this may seem like a subtle way to deal with the Rate Limit, the number of occurrences has dropped to almost zero since its introduction.
͜ͷΈͰඅ༻Λ͑ΒΕ͓ͯΓɺྦྷܭͰ ઍສՊఔΛϕΫτϧԽ͕ͨ͠ɺඅ༻΄ͱ ΜͲֻ͔͍ͬͯͳ͍ • Use Redis as vector cache storage • Thanks to this mechanism, a total of about tens of millions of accounts have been vectorized so far, but at little or almost no cost. • Embedding API ͕͓͔͑ͨ͛ͰɺGPU େྔͷ CPU/ϝϞϦΛ٧ΜͩߴՁͳϚγϯ͕ෆཁʹ Embedding API eliminates the need for expensive machines packed with GPUs and lots of CPU/memory
DB Receipt.pdf, jpg, etc… [[-0.03455162],[-0.01306203],…, [ 0.00694819],[-0.01055199]] User • Vectorize the text of the contents of the receipt • OCR, use ChatGPT, etc… • Then store it in Vector DB, etc • ྖऩॻͷதͷςΩετΛ༧ΊϕΫτϧԽ • OCR, ChatGPT ʹ͛Δ etc… • ͦΕΛ Vector DB ͳͲʹอଘ͓ͯ͘͠ Vectorization Upload
DB • Ϣʔβ͕ೖྗͨ͠ݕࡧϫʔυΛϕΫτϧԽɺ DB ্ͷ͔Β͍ۙ͠ͷΛϐοΫ User • Vectorize search words entered by the user, and pick the closest ones from the values on the DB. 12/1ͷ1ສԁͷྖऩॻ A receipt of10,000 yen on December 1. [[-0.03455162],[-0.01306203],…, [ 0.00694819],[-0.01055199]] Search Receipt_Dec_1.pdf Vectorization
a certain receipt. Vector DB • Text to File ͕Ͱ͖ΕɺͪΖΜ File to File ࣮ͩͬͯͰ͖ͪΌ͏ • If Text to File can be implemented, of course File to File can also be implemented. ͜Εͱྨࣅͷྖऩॻ͕΄͍͠ I need a receipt similar to this one. [[-0.03455162],[-0.01306203],…, [ 0.00694819],[-0.01055199]] Text extraction Vectorization Receipt, Dec. 1, … Search
sentence vectors ςΩετʹมͰ͖ΔͷͳΒɺͳΜͰϨίϝϯυ etc Λ࣮Ͱ͖Δɻ Anything that can be converted to text can be used to implement recommendations, etc. ͔͠ ChatGPT ͷ͓ӄͰɺը૾ etc ΛςΩετʹม͢Δෑډ͘ͳ͍ͬͯΔ Also, thanks to ChatGPT, the difficulty of converting images and other data to text has been reduced.
• OpenAI's Embedding API made implementing an AI solution for a team without an ML engineer easy and inexpensive. • Embedding API Λ׆༻͢Δ͜ͱͰɺϨίϝϯυҟৗݕग़ɺςΩ ετྨͳͲଟ༷ͳιϦϡʔγϣϯΛ࣮ݱͰ͖Δ • Embedding APIs can be used to implement various solutions such as recommendation, outlier detection, text classification, etc. ·ͱΊ - Summary