# Mastering LLMs for Source Code Classification: From Hype to Hands-On Success

- Speaker: [Ori Abramovsky](/wiki/speakers/ori-abramovsky.md)
- Event: [Reversim Summit 2024](/wiki/years/2024.md)
- Video: https://www.youtube.com/watch?v=2duNtWZogRg
- Transcript: [/transcripts/2024/05-2duNtWZogRg.md](/transcripts/2024/05-2duNtWZogRg.md)
- Language: Hebrew · Type: talk · Level: intermediate
- Topics: [Machine Learning](/wiki/topics/machine-learning.md), [AI and LLMs](/wiki/topics/generative-ai.md), [Security](/wiki/topics/security.md), [Python](/wiki/topics/python.md)

> Written by an LLM from machine transcripts. It can contain errors. Check the transcript before you quote it.

## Summary

The speaker presents a practical, anti-hype approach to using Large Language Models for source code classification, specifically targeting malicious open source packages. Through real research examples, the speaker discusses how to select the right open-source LLMs, manage context windows, ensure classification determinism, and refine prompt engineering. The audience learns actionable strategies to apply LLMs effectively in security applications while avoiding common pitfalls.

## Key points

- [1:16](https://www.youtube.com/watch?v=2duNtWZogRg&t=76s) The talk focuses on a real-world case study of using LLMs to automatically classify malicious open source packages.
- [4:20](https://www.youtube.com/watch?v=2duNtWZogRg&t=260s) Attackers exploit package manager installation scripts to execute arbitrary malicious code upon installation.
- [8:18](https://www.youtube.com/watch?v=2duNtWZogRg&t=498s) Smaller open-source LLMs like CodeLlama can be run locally on a CPU to reduce costs and fit specific use cases.
- [10:53](https://www.youtube.com/watch?v=2duNtWZogRg&t=653s) Choosing an LLM with an appropriate context window is critical since source code requires larger token capacities than typical text.
- [13:09](https://www.youtube.com/watch?v=2duNtWZogRg&t=789s) To build a reliable classification application, developers must configure the LLM for determinism rather than relying on random optimizations.
- [19:48](https://www.youtube.com/watch?v=2duNtWZogRg&t=1188s) Asking the LLM to provide reasoning alongside its classification helps debug edge cases and understand its decision-making.
- [21:54](https://www.youtube.com/watch?v=2duNtWZogRg&t=1314s) Using techniques like impersonation and keeping prompts concise prevents the model from missing critical instructions due to attention limits.

## Takeaways

- Select LLMs carefully by matching their context window size and parameter count to your specific source code use case.
- Disable non-deterministic sampling when building classification apps to ensure consistent and reliable outputs.
- Ask the LLM to explain its classification reasoning to effectively debug false positives and false negatives.
- Keep prompts concise and aligned with the model's native terminology to avoid ambiguity and hallucinations.

## Questions this talk answers

- How can I ensure deterministic outputs from an LLM for classification tasks?
- What is the best way to handle large source code files when LLM context windows are limited?
- How do I debug why an LLM is misclassifying certain code snippets?

## Technologies

Python, JavaScript, CodeLlama, TinyLlama, Falcon, GPT-4, PyPI, NPM

## Tags

llm, machine learning, malware detection, prompt engineering, python, source code security
