<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Emre Atilgan on Medium]]></title>
        <description><![CDATA[Stories by Emre Atilgan on Medium]]></description>
        <link>https://medium.com/@emreatilgan?source=rss-d45bdca7ba68------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*UKwxQTR8C89biG6oxVOgqQ.jpeg</url>
            <title>Stories by Emre Atilgan on Medium</title>
            <link>https://medium.com/@emreatilgan?source=rss-d45bdca7ba68------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 15:22:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@emreatilgan/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Data Scientist in the Loop: How I Implemented a Complex Recommendation System with Claude AI]]></title>
            <link>https://medium.com/@emreatilgan/data-scientist-in-the-loop-how-i-implemented-a-complex-recommendation-system-with-claude-ai-0ea9c8b9ed0b?source=rss-d45bdca7ba68------2</link>
            <guid isPermaLink="false">https://medium.com/p/0ea9c8b9ed0b</guid>
            <category><![CDATA[recommendations]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[human-ai-collaboration]]></category>
            <dc:creator><![CDATA[Emre Atilgan]]></dc:creator>
            <pubDate>Fri, 06 Dec 2024 16:15:50 GMT</pubDate>
            <atom:updated>2024-12-06T16:15:50.044Z</atom:updated>
            <content:encoded><![CDATA[<h3>Implementing P-Companion paper with Claude AI</h3><p>As a data scientist following the rapid evolution of LLMs, I recently decided to tackle an interesting challenge: implementing a complex research paper using Claude AI as my coding partner. The paper in question was “P-Companion: A Principled Framework for Diversified Complementary Product Recommendation” [1] from Amazon. My journey working with an AI brings this blog to life.</p><p>Implementation repository: <a href="https://github.com/emreatilgan/P-Companion">https://github.com/emreatilgan/P-Companion</a></p><h4>The Setup: Teaching an AI About the Paper</h4><p>The first step was getting Claude up to speed with the paper. Instead of uploading the PDF directly, I went with a more structured approach — feeding the paper section by section, along with key figures. This helped ensure Claude had a clear understanding of the architecture, particularly the crucial components:</p><figure><img alt="P-Companion Architecture Figure from the paper showing Product2Vec, Type Transition, and Item Prediction modules" src="https://cdn-images-1.medium.com/max/894/1*6ZZSW7-fd_Pz2znxkmgiyw.png" /></figure><p>The paper introduces a sophisticated approach to product recommendations that considers both relevance and diversity — something anyone who recommended three identical tennis rackets can appreciate!</p><h4>Building the Codebase: AI as a Coding Partner</h4><p>What surprised me most was how collaborative the coding process became. Rather than just getting dumps of code, working with Claude felt more like pair programming with a very knowledgeable (if occasionally quirky) colleague.</p><p>The initial project structure emerged through our dialogue:</p><pre>src/<br>  models/<br>    product2vec.py      # Graph-based embeddings<br>    type_transition.py  # Type prediction<br>    item_prediction.py  # Final recommendations<br>    p_companion.py     # Main model<br>  data/<br>    data_loader.py<br>    bpg.py            # Behavior Product Graph<br>    synthetic_data.py  # Test data generation<br>  utils/<br>    metrics.py<br>    constants.py</pre><p>One thing I learned quickly: while Claude writes good code, you need to be methodical in reviewing and testing it. Every piece of code went through:<br>1. Initial implementation review<br>2. Git commit with clear descriptions<br>3. Testing in isolated feature branches<br>4. Error analysis and iteration</p><pre>main<br>  \<br>   feat/initial-implementation<br>    \<br>     feat/test-implementation<br>      \<br>       feat/synthetic-data-generator<br>        \<br>         fix/product2vec-as-pretrained-emb</pre><h4>The Dance of Error Messages</h4><p>Perhaps the most interesting part was the error-fixing process. When running into issues like:</p><pre>RuntimeError: Index tensor must have the same number of dimensions as input tensor</pre><p>Claude was exceptionally good at understanding error contexts and proposing fixes. But here’s the key: you need to be precise in reporting errors and validating fixes. Each error became its own mini-investigation, leading to better code quality.</p><h4>Synthetic Data: Making it Work Without Real Data</h4><p>One challenge we faced was testing without access to Amazon’s actual product data. The solution? A synthetic data generator that mimics the paper’s described behavioral patterns. This actually turned out to be a blessing in disguise — it forced us to deeply understand the paper’s data requirements.</p><h4>The Results</h4><p>After all the iterations, we got the model training end-to-end:</p><pre>Epoch 20/20: loss=0.0936<br>Validation Metrics:<br>hit@1: 0.0007<br>hit@3: 0.0211<br>hit@10: 0.0627<br>type_diversity: 1.0000<br>mean_relevance: -0.0612</pre><p>While these initial results leave room for improvement (hello, negative mean relevance!), they prove the concept: that complex research implementations are now accessible through AI collaboration.</p><h4>Journey Update: Making Product2Vec Work as Intended</h4><p>After successfully getting the codebase to run end-to-end, we discovered a crucial insight: Product2Vec should learn embeddings for ALL products, not just the ones used in similarity pairs. This realization came directly from the paper:</p><blockquote><em>Product2vec starts with taking each item’s title and category features as input and applies an universal embedding module FFN(·), which consists of three feed-forward layers with a batch normalization layer, to all items i identically to obtain initial k-dimensional embeddings…</em></blockquote><p>This led to a significant refactoring of our implementation, highlighting an important aspect of AI-assisted development: the need to carefully validate against source materials.</p><h3>The Power of Reading Papers Carefully</h3><p>One interesting thing I learned from this implementation was how crucial it is to read research papers carefully. Even with AI assistance, subtle details like “applies to all items identically” can significantly impact the implementation. This exemplifies why having a data scientist in the loop is essential — we need human expertise to catch and interpret these nuances.</p><h3>Next Steps</h3><p>While we have a working implementation, there’s room for improvement:</p><ol><li>Model Performance:</li></ol><ul><li>Investigate the negative mean relevance</li><li>Improve embedding quality</li><li>Fine-tune model parameters</li></ul><p>2. Data Quality:</p><ul><li>Adjust synthetic data distributions</li><li>Better complementary relationship modelling</li><li>More realistic behavioural patterns</li></ul><p>3. Analysis:</p><ul><li>Add embedding visualisation</li><li>Study type transition patterns</li><li>Analyse failure cases</li></ul><h3>Lessons Learned</h3><ol><li>AI is a powerful implementation partner but requires human oversight:</li></ol><ul><li>Can handle complex code generation</li><li>Needs guidance on architectural decisions</li><li>Benefits from human domain knowledge</li></ul><p>2. Paper implementation requires iterative refinement:</p><ul><li>Start with basic functionality</li><li>Add complexity gradually</li><li>Validate against paper details</li></ul><p>3. Good development practices remain crucial:</p><ul><li>Clear git commit history</li><li>Proper code organization</li><li>Comprehensive testing</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nHQEYMfUTbhyFsXWP09s3g.jpeg" /><figcaption>Created by Flux AI</figcaption></figure><h4>AI Collaboration Disclosure</h4><p>This blog post and the described implementation were developed using Anthropic’s Claude AI (version 3.5 Sonnet) as a technical collaborator. While Claude assisted with code generation, technical writing, and problem-solving, all content was carefully reviewed, edited, and validated by a human data scientist. The implementation decisions, code reviews, and mathematical validations were performed with human oversight. This collaboration serves as a case study in human-AI paired development while respecting both intellectual property rights and the need for transparency in AI-assisted content creation.</p><h4>Conclusion</h4><p>The journey of implementing P-Companion demonstrates the evolving nature of data science work. Working with AI tools like Claude doesn’t eliminate the need for human expertise — it transforms how we apply it. The future of data science likely involves this kind of collaborative implementation, where AIs handle the heavy lifting of code generation while humans focus on understanding, validation, and refinement.</p><h4>References</h4><p>[1] Junheng Hao, Tong Zhao, Jin Li, Xin Luna Dong, Christos Faloutsos, Yizhou Sun, and Wei Wang. 2020. P-Companion: A Principled Framework for Diversified Complementary Product Recommendation. In Proceedings of the 29th ACM International Conference on Information &amp; Knowledge Management (CIKM ‘20). Association for Computing Machinery, New York, NY, USA, 2517–2524. <a href="https://doi.org/10.1145/3340531.3412732">https://doi.org/10.1145/3340531.3412732</a></p><p>[2] Implementation repository: <a href="https://github.com/emreatilgan/P-Companion">https://github.com/emreatilgan/P-Companion</a></p><p>[3] Claude AI (Version 3.5 Sonnet, October 2024). Anthropic. <a href="https://www.anthropic.com/claude">https://www.anthropic.com/claude</a></p><p>[4] Anthropic. (2024). Claude Documentation. <a href="https://docs.anthropic.com/">https://docs.anthropic.com</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0ea9c8b9ed0b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>