Academic Jobs - Home of Higher Ed Logo

Research Spotlight: Hamid Abdul Basit on Teaching Search Engines to Find Code Clones

9 min read15 views

At a glance

Hamid Abdul Basit and co-authors built Clone-Seeker, which indexes code by plain-language keyword documents and beats the state of the art on semantic clone recall.

lines of HTML codes
Photo by Florian Olivo on Unsplash

The best way to find a piece of code that does what you want may be to stop searching the code and start searching a short, plain-language note attached to it. That is the bet behind a 2022 study in IEEE Access, which reports that giving each code fragment a document of descriptive keywords, drawn partly from the code's own identifiers and partly from a human-written description of what that family of code does, let a fairly ordinary search engine surface semantically similar code at higher recall than the state-of-the-art approaches it was benchmarked against.

The paper, "Clone-Seeker: Effective Code Clone Search Using Annotations," is by Muhammad Hammad, Önder Babur, Hamid Abdul Basit and Mark van den Brand, and it ran in IEEE Access in January 2022, volume 10, pages 11,696 to 11,713. Basit is listed on the paper with Prince Sultan University in Riyadh; he now holds an associate professorship in computing and technology at IQRA University in Islamabad, where his research has circled clone detection and software similarity for more than fifteen years. The co-authors come from Eindhoven University of Technology in the Netherlands.

The premise is unglamorous and hard to argue with: developers spend real working hours hunting for code that already does what they need, whether to reuse it directly, to transplant a fix, or to compare competing implementations. Existing tools match text. Developers are usually matching intent.

Four kinds of duplicate, and only one of them looks duplicate

The research community sorts code clones into a rough ladder. Type-1 clones are identical apart from whitespace and comments. Type-2 clones have the same structure but renamed identifiers. Type-3 clones are near-misses, with statements added or removed. Type-4 clones are the hard case: snippets that share almost no syntax but implement the same functionality, one written with a for-loop and one with a stream, say, or one using a library call where the other hand-rolls the logic.

Any token-matching tool catches the first three reliably. The fourth is where search breaks down, and it is the case that matters most for the tasks the paper names: automated software transplantation, software diversification and software repair. All three start with a retrieval problem, and all three are useless if the retrieval returns the obvious textual copy instead of the alternative implementation.

BigCloneBench, the benchmark most clone research is measured against, is built for exactly this difficulty. It contains more than eight million manually validated clone method pairs drawn from IJaDataset, a Java repository of 2.3 million source files, roughly 365 million lines of code, from 25,000 open-source projects. Those pairs are grouped into 43 clone classes, each corresponding to a distinct functionality.

What goes on the index card

Clone-Seeker does not index source code. It indexes a document about the source code. Think of a library that has given every folder of code a handwritten index card listing what the code does in ordinary words, then thrown away the folders and searched only the cards.

Building those cards took several passes. The team pulled 14,922 true-positive clone methods out of BigCloneBench, traced them into the underlying IJaDataset files, then stripped each method of Java reserved keywords, constant values, whitespace and comments. The cleaned code went through a tokenizer, the Javalang library, which provides a Java 8 lexer and parser in Python. Identifiers were split on camelCase and snake_case boundaries, single characters were dropped, and the remaining words were stemmed to their roots so that related forms collapse together.

Comments were deliberately excluded. The authors cite prior findings that comments are an unreliable and inconsistent source of natural-language text, note that some comments in IJaDataset are written in languages other than English, and point out that an outdated comment may describe code it no longer matches.

That produced half of each card. The other half came from the clone class: a short list of keywords describing what the whole family of snippets does. The team built this two ways. In the manual version, a person wrote the description. In the automatic version, a script counted the most frequent words across every method in the class and kept the top few.

Concatenate the two lists and you have a natural-language document for each method. Retrieval itself used TF-IDF, the classic weighting scheme that scores a term by how often it appears in a document, discounted by how common it is across the whole collection — a term like "file" counts for little because it is everywhere, while "circumference" counts for a lot. That is a deliberately plain choice, and the authors describe it as a proof of concept rather than a destination. The full text and the result tables are readable in the open-access PDF hosted by Eindhoven University of Technology.

Lines of colorful JavaScript code displayed on a dark screen

Photo by Markus Spiske on Unsplash

Manual annotation wins on natural-language queries

The paper's own worked example is a query typed the way a frustrated developer would type it: "Error while copying files from source to destination java." After preprocessing it becomes "error copi file source destin java," and the top-ranked result is a method whose keyword document covers copying a file from source to destination, along with a batch of stream and reader-writer terms. It scored 0.464 against the query.

To measure this properly, the team used two standard information-retrieval metrics: mean reciprocal rank, which averages one over the position of the first correct hit, so a correct answer in slot one scores 1.0 and a correct answer in slot three scores 0.33; and precision at ranks 1, 5 and 10, which asks how many of the top results belong to the right clone class.

On BigCloneBench, with natural-language queries, the manual variant beat both the automatic variant and the identifiers-only baseline at p < .00001. The automatic variant, by contrast, was statistically indistinguishable from the baseline at p = .42074. The authors' explanation is almost embarrassingly simple: manual annotations and natural-language queries are both written by people, so their vocabularies overlap.

On code-to-code search in the same benchmark, the paper reports the best recall for Type-4 semantic clones among the approaches it was compared against, including the token-based detectors that dominate the field. The published version, with its full result tables, is available through the DOI record for the IEEE Access paper.

A second dataset tests whether the idea travels

A single benchmark proves little, so the team repeated the exercise on Project CodeNet, a collection mined from online judge sites where programmers submit solutions to set problems and an automatic reviewer grades them. CodeNet's Java portion holds 250 problems with roughly 300 sample solutions each, syntactically or semantically similar to one another.

The researchers filtered those down to problems generic enough that their solutions are discussed on Stack Overflow and GeeksforGeeks, then built a benchmark of 46 queries covering the remaining classes. The finding split down the middle. With natural-language queries, manual annotation again won outright, at p < .00001. With code used as the query, none of the three variants separated from the others: the difference came in at p = 0.06, short of significance.

That second result is worth dwelling on, because it is the one the authors do not spin. On Project CodeNet, adding annotation to a query made of code terms did not measurably help. The paper states plainly that better annotation techniques need to be explored before the manual and automatic variants can beat the plain baseline for code-to-code search.

The catch: a human still has to write the description

Here is where the paper puts its own brakes on. The variant that performs best depends on a person writing a description for every clone class. That is fine for 43 classes. It is not obviously fine for the millions of distinct behaviours inside a large industrial code base, and it hands a tedious, expert task to exactly the people with the least spare time.

Automatic annotation was supposed to solve that, and in this study it did not. As the authors put it, "adding more tokens in terms of automatic annotation does not improve the search a lot and different annotation techniques are required to explore in the future." They also flag that they tested only a narrow set of threshold values for how many keywords to keep, that word counting was the only automatic extraction method tried, and that the natural-language queries, though collected from real websites, do not cover everything a developer might ask.

A cautious reader might push harder. If manual annotation wins mostly because it shares vocabulary with human-written queries, then part of the gain reflects a matching style rather than evidence that the system understands what code does. The comparison set for that victory is also an internal baseline built from identifiers alone, so beating it is not the same as beating a commercial code search product. And the paper's evaluations cover two Java datasets; nothing here was tested on C++, Python or a production monorepo with years of drift in it.

The study is published open access under a Creative Commons Attribution 4.0 licence, which means the tables and the corpus construction steps can be checked and reused rather than taken on trust — a small but real advantage for anyone wanting to replicate or extend the work.

a computer screen with a bunch of text on it

Photo by Rahul Mishra on Unsplash

Where this goes next

The authors lay out a fairly clear itinerary. TF-IDF was a placeholder; word2vec and GloVe embeddings are the obvious next step, and they suggest joint neural network models trained on both the natural-language documents and the code itself. Keyword extraction could move beyond word frequency to techniques like word degree or RAKE. Evaluation could widen to other clone datasets, and the approach could be tried on coarser granularities than methods — structural clones, the design-level similarities Basit has been publishing on since his PhD at the National University of Singapore, and clones of entirely different artifacts such as models.

There is a practical lesson buried in the null results. Two of the paper's three headline experiments found that a cheap, boring representation, a bag of English words, was enough to improve retrieval, while the clever automatic substitute added nothing. Systems that retrieve code for a living — the suggestion engine in an IDE, the assistant that autocompletes a method, the pipeline deciding which snippets are worth learning from — are being tuned and retrained at enormous expense right now. Clone-Seeker suggests that the supply of good human-written descriptions of what code does may matter as much as the sophistication of the model reading them, and that a catalogue card written by someone who understands the code still beats a word count.

  • information-retrieval
  • software-engineering-research
  • ieee-access
  • code-clone-search
  • clone-seeker
Portrait of Jarrod Kanizay
About the author

Jarrod KanizayView author

Academic Jobs In House Author

Visionary leader transforming academic recruitment with 20+ years in higher education.

Acknowledgements:

Discussion

Sort by:

Be the first to comment on this article!

You

You’ll be asked to sign in before your comment is posted.

Browse by Faculty

Browse by Subject

Frequently Asked Questions

🔍What is Clone-Seeker?

Clone-Seeker is a code search technique described in a 2022 paper in IEEE Access by Muhammad Hammad, Önder Babur, Hamid Abdul Basit and Mark van den Brand. Instead of indexing raw source code, it builds a short natural-language document for every code fragment, combining keywords from the code's own identifiers with keywords describing the clone class. Searches are then matched against those documents using TF-IDF, a standard term-weighting scheme.

🧩What is a code clone, and why are there different types?

A code clone is a fragment of code that is syntactically or semantically similar to another fragment. Researchers sort them into Type-1 (identical except for whitespace and comments), Type-2 (renamed identifiers), Type-3 (near-misses with statements added or removed) and Type-4 (same functionality, different syntax). The Clone-Seeker paper focuses on the difficulty of retrieving Type-4 clones, because a snippet that shares no vocabulary with the query is invisible to text matching.

🗂How did the researchers build the keyword documents?

They extracted 14,922 true-positive clone methods from BigCloneBench and traced them into IJaDataset. Each method was stripped of Java reserved keywords, constants, whitespace and comments, tokenized with the Javalang library, split on camelCase and snake_case boundaries, and stemmed to root words. Separately, keywords describing the whole clone class were added, either from a human-written description or from the most frequent words across every method in the class.

🚫Why were code comments left out of the metadata?

The authors cite prior research showing that comments are an unreliable and inconsistent source of natural-language text. Some comments in IJaDataset are written in languages other than English, and an outdated comment may no longer describe the code beneath it. Since the method targets English queries, using comments would have introduced noise the team could not control for.

📊What did the experiments on BigCloneBench show?

With natural-language queries, the manually annotated variant of Clone-Seeker outperformed both the automatically annotated variant and the identifiers-only baseline at p < .00001. The automatic variant was statistically indistinguishable from the baseline at p = .42074. On code-to-code search, the paper reports the best recall for semantic Type-4 clones among the approaches it was compared with.

⚖️What happened when the team tested on Project CodeNet?

The results split. With natural-language queries, manual annotation again won clearly at p < .00001. With code used as the query, none of the three variants separated from the others: the difference was p = 0.06, short of statistical significance. The authors state that better annotation techniques need to be developed before annotation can beat the plain baseline for code-to-code search.

✍️Why did manual annotation beat the automatic version?

Both manual annotations and natural-language search queries are written by people, so their vocabulary overlaps. Automatic annotation, built by counting the most frequent words across a clone class, tends to produce terms that do not resemble the way a developer phrases a query. The paper reports that adding more tokens through automatic annotation did not improve search much at all.

⚠️What are the main limitations the authors acknowledge?

Clone-Seeker in its best-performing form depends on a person writing a description for each clone class. The team tested only a limited set of threshold values for how many keywords to keep, and word counting was the only automatic keyword extraction method they tried. They used a finite set of natural-language queries collected from websites, and they evaluated on two Java datasets only, leaving other languages and other clone datasets untested.

🧭What does the paper propose for future work?

The authors name several directions: replacing TF-IDF with word2vec or GloVe embeddings, trying joint neural network models trained on both the keyword documents and the code, testing other keyword extraction techniques such as word degree or RAKE, extending evaluation to other clone datasets, and applying the approach to coarser granularities such as structural clones and model clones rather than individual methods.

📄Where can I read the full paper?

The paper is open access. The complete text and result tables are available through the DOI record and as a PDF hosted by Eindhoven University of Technology.

🎓Who is Hamid Abdul Basit?

Hamid Abdul Basit is an associate professor of computing and technology at IQRA University in Islamabad, Pakistan. He is listed on the Clone-Seeker paper with Prince Sultan University in Riyadh. His research centres on code clones, software similarity and reuse, including structural clone detection, clone visualization and code recommendation tools. He earned his PhD in software engineering at the National University of Singapore.

🏗Why should anyone outside software engineering care?

Because the code search problem is now infrastructure. Automated repair, security patching that has to find every variant of a vulnerable function, and the retrieval layer beneath AI coding assistants all depend on finding code by what it does rather than what it says. Clone-Seeker's results suggest the quality of human-written descriptions of code remains a real constraint, which is an argument for keeping documentation in the loop rather than treating it as overhead.