Sub topic 6
Training data and memorized output
This chapter assumes you know what an open-source license is, can use an AI coding assistant, and understand the copyright basics from earlier chapters. It is general education, not legal advice. The law differs by country and is still changing.
What the model learned from
A code model is trained on very large collections of text and source code. Much of that code is public, and much of it is under open-source licenses. Some of it has no license at all, which usually means all rights are reserved by the author.
Training does not store files in a folder. The model adjusts numeric weights so that it can predict the next token. The result is a statistical summary of the training data, not a copy of it. Whether training itself is lawful is a separate question that courts and legislatures in different countries are still working through. This chapter focuses on a narrower, practical question: what happens when the output looks like something from the training data.
What memorization is
Memorization is when a model reproduces a passage from its training data nearly verbatim. It is most likely when:
- The code appeared many times in the training data, such as a popular utility or a license header.
- The code is distinctive, with unusual names, comments or structure.
- The prompt contains the start of the original, such as a function name and a matching docstring.
- The task is narrow enough that very few implementations are plausible.
Most generated code is not memorized. It is a new combination of common patterns. But the rate is not zero, and you cannot tell by reading the output whether a given snippet is original.
Common ways it goes wrong
- Short, common code is treated as a risk. A three-line loop is usually not protectable, because there are few ways to write it. Long or unusual passages carry more risk, so size and originality both matter.
- Obvious markers are ignored. If a suggestion contains a copyright line, a license notice, or an author's name, treat it as a strong sign of copying.
- Reasoning that "the AI wrote it" removes the obligation. If the output reproduces licensed code, the original license terms can still apply. The tool's involvement does not remove them.
- Assuming the tool's filter is complete. Some tools offer a setting that blocks suggestions matching public code. It lowers the risk but does not remove it, because it only catches matches the tool can detect.
Practical checks
You can reduce risk with a few habits:
- Turn on any public-code matching filter your tool offers, and note in your policy that you did so.
- Be suspicious of long, polished functions that appear in response to a short prompt.
- Search for distinctive lines, such as an unusual constant or comment, in a code search engine.
- Run a license or snippet scanner in CI if your organization uses one.
- When you find a match, either comply with the original license, which means keeping its notice and meeting its conditions, or rewrite the code yourself without copying its structure.
Rewriting works best when you understand the behavior and write from the requirement, not by lightly editing the matched code. A renamed copy is still a copy.
Why it connects to licensing
If memorized code is permissively licensed, such as MIT, the main duty is usually to keep the copyright and license notice. If it is under a copyleft license, such as the GPL, reuse can bring stronger conditions on how you distribute your own code. The next chapter covers these obligations in detail.
Exercise
A coding assistant returns a 40-line function that includes a comment naming an author and a project you do not recognize. Name two steps you should take before committing it.
Show answer
Search for the distinctive comment or lines in a code search engine to find a possible original and check its license. Then either comply with that license, including keeping its notice, or rewrite the function from the requirements without copying it. Reporting the match to your team's license contact is also reasonable.
Exercise
A teammate says a snippet is safe because "the model generated it, so it is new." Why is this reasoning unreliable?
Show answer
A model can reproduce training data nearly verbatim, so the output may be a copy of licensed code. Where it is, the original license can still apply no matter which tool produced the text.