<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>An Automated Evaluation Approach for Jupyter Notebook Code Cell Recommender Systems</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Selin Aydin</string-name>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Dennis Mertens</string-name>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Ouyu Xu</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>ETH Zurich</institution>
          ,
          <addr-line>Zurich 8092</addr-line>
          ,
          <country country="CH">Switzerland</country>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>Research Group Software Construction RWTH Aachen University</institution>
          ,
          <addr-line>Ahornstraße 55, 52074 Aachen</addr-line>
          ,
          <country country="DE">Germany</country>
        </aff>
      </contrib-group>
      <fpage>4</fpage>
      <lpage>11</lpage>
      <abstract>
        <p>The reuse of code within Jupyter Notebooks is an often overlooked concept, resulting in the loss of valuable knowledge that could be retrieved from already created Notebooks. Presently, the reuse of Jupyter Notebooks is particularly impeded by the absence of suitable reuse approaches and tools. This paper presents a code cell recommender system in the form of the JupyterLab extension, designated as JupyRecSys. Moreover, we propose an automatic evaluation framework in the form of the CL-tool CelRecEval, which allows developers to evaluate and compare the performance of cell recommender systems. The evaluation capabilities of CelRecEval are demonstrated by applying it to JupyRecSys. The resulting high metric scores demonstrate that JupyRecSys can correctly recommend and rank relevant cells. Moreover, the generation of more detailed performance reports enabled the identification of specific characteristics of code cells that negatively impact the performance of the cell recommendation system.</p>
      </abstract>
      <kwd-group>
        <kwd>eol&gt;Jupyter Notebook</kwd>
        <kwd>Recommender System</kwd>
        <kwd>Machine Learning</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1. Introduction</title>
      <p>
        The Jupyter Notebook (Notebook for short) has become
a widely utilized tool in academia and industry for
prototyping Python ML solutions due to their flexibility and
interaction. Studies have demonstrated that code from other
Notebooks is frequently reused through copy-paste. In
particular, code for importing packages and visualizing data
is often duplicated [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ]. An analysis by Källen et al. of 2.7
million Notebooks on GitHub found that 70% of the code
snippets contained are identical to others, difering only
in whitespace, and nearly 50% of all Notebooks contain no
unique code at all [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ]. Currently, Notebooks lack reusability
concepts. This issue has been discussed in various
publications, and initial solutions have been proposed as best
practices or JupyterLab extensions [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ][
        <xref ref-type="bibr" rid="ref4">4</xref>
        ].
      </p>
      <p>An initial challenge is to identify and locate relevant code
from previous Notebooks. While search systems can be
used for this purpose, they require manual intervention by
the developer. The success of the search depends on the
keywords used. An alternative approach would be to use
a recommender system that suggests relevant cells from
previous Notebooks to match the current cell. This would
significantly reduce the efort required, as no action by the
developer would be necessary.</p>
      <p>A Notebook cell recommendation system (cell
recommender for short) implements a special form of code
recommendation, suggesting similar code cells instead of code
completions. Cell recommenders have not yet been explored,
and an evaluation method for them has not yet been
developed.</p>
      <p>The paper is structured as follows: Section 2 presents an
overview of existing tools and methods to reuse Notebooks.
In Section 3, we state the research goals and contributions of
the paper. Then, in Section 4, we present a cell
recommendation strategy. Next, Section 5 presents a general evaluation
framework for cell code recommenders. Section 6 describes
the implementation of the recommendation strategy and
the evaluation framework. The setup and results of the
evaluation are discussed in Section 7; the research questions
are answered in Section 8. After presenting the threats to
validity in Section 9, Section 10 concludes the paper and
gives an outlook for potential future work.
This section reviews recent tools and methods to improve
the code reusability of Notebooks and their evaluation
approaches.</p>
      <p>
        JupySim, developed by Horiuchi et al., models Notebooks
as directed acyclic graphs to identify the relational
structures between code, data, and outputs [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ]. The system has
proven efective in identifying the most similar Notebooks
based on user queries. However, its complex, detailed
graphbased query construction may impede user adoption for
regular Notebook reuse. Additionally, JupySim is currently
only available as a separate web interface, suggesting the
potential for a more integrated JupyterLab solution.
Unfortunately, the authors do not provide an evaluation approach
or results.
      </p>
      <p>
        The Elyra code snippet JupyterLab extension represents
a further significant addition to the Jupyter ecosystem [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ].
Users can label specific code cells within any Notebook,
save them to the global extension code database, and
retrieve them via text or label queries. Despite Elyra’s ease
of integration and improved searchability, it relies heavily
on manual user intervention. The necessity for users to
repeatedly identify and label reusable code snippets could
potentially be a source of frustration, particularly for those
with extensive code bases.
      </p>
      <p>While JupySim ofers a sophisticated graph-based
approach to identifying similar Notebooks, its complexity and
standalone nature may not be optimal for everyday use.
In contrast, Elyra, with its integrated JupyterLab
interface, streamlines code snippet reuse but necessitates manual
labeling and does not support the reuse of entire Notebooks.</p>
      <p>
        A first step towards an automated solution is Typhon
[
        <xref ref-type="bibr" rid="ref7">7</xref>
        ], an approach for recommending Notebook code cells
based on Markdown text similarity. The authors
evaluate Typhon twofold. First, they manually request and
review recommendations for Markdown-code-pairs
containing Matplotlib plot and chart code. For this, they add suitable
Markdown-text to chosen code cells. The Markdown-text
from these Markdown-code-pairs is then used to query
recommendations. The authors evaluate a recommendation
as correct if the recommended code is the same as in the
query Markdown-code pair. The authors rated the
resulting accuracy as moderate. Due to the evaluation setup, the
generalizability and comparability are limited. It has to be
noted that 30,93% of public Notebooks on GitHub do not
contain a single Markdown cell [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ]. Further, Typhon is not
yet publicly available.
      </p>
    </sec>
    <sec id="sec-2">
      <title>3. Research Goals and Contributions</title>
      <p>Given the strengths and limitations of the existing
approaches, our current work is focused on addressing these
gaps by answering the following research questions (RQ):
RQ1: What can a cell recommendation strategy look like
that makes suggestions to the developer during the
programming of a cell?
RQ2: How can an approach for the automatic quantitative
evaluation of the performance of cell recommenders
look like?</p>
      <p>By answering these questions, this paper makes the
following contributions to improve the reusability of
Notebooks:
• A cell recommendation strategy specialized for</p>
      <p>Python Notebooks implementing ML tasks.
• A general framework to quantitatively evaluate cell
recommenders implementing this strategy.
• The JupyterLab extension JupyRecSys which
implements the cell recommendation strategy.
• The CL-tool CelRecEval which implements this
evaluation approach.
• The results of applying CelRecEval to evaluate the
performance of the cell recommender JupyRecSys.</p>
    </sec>
    <sec id="sec-3">
      <title>4. A Cell Recommendation Strategy</title>
      <p>In this section, we present a recommendation strategy for
cell recommenders. A cell recommender that suggests code
based on similarity to a query cell is classified as a
contentbased recommender. Since it only provides the top-k most
similar cells, we refer to it as a top-k cell recommender.</p>
      <p>A common approach in such recommenders is to embed
recommendation items in a semantic vector space. This has
several advantages. First, it significantly reduces the
complexity of the items, e.g., code, syntax, semantics, variables,
symbols, etc. Further, a vector representation within a
semantic vector space allows the recommender to eficiently
determine similarities using various distance metrics, such
as cosine similarity or Euclidean distance. In the vector
space, the proximity of vectors directly reflects the degree
of similarity between them. At the same time, the results
remain interpretable because distances between vectors are
easy to comprehend.
 Notebook Cell </p>
      <p>Classify Task</p>
      <p>Tokenize
Cell Tokens
Generate</p>
      <p>Embedding 
Task Label</p>
      <p>Cell Embedding
Build Embedding</p>
      <p>Labeled Cell
Embedding</p>
      <p>First, we explain how code cells are transformed into a
vector representation in a semantic vector space, resulting
in a cell embedding as output. Then, we present the process
of transforming and loading, which stores cell embeddings
in an appropriate database. Finally, we explain how
recommendations are provided using the stored cell embeddings.</p>
      <sec id="sec-3-1">
        <title>4.1. Embedding Cells</title>
        <p>When code cells are transformed into vector representations
and embedded in a vector space, they are particularly close
to each other if they represent similar code. To further
reduce the search space around a cell embedding and get
more accurate results, each cell embedding is labeled with
the ML task it implements.</p>
        <p>The embedding process is shown in Figure 1 as a UML
activity diagram. The input is a single Notebook cell. The
process consists of two parts that are executed in parallel.
The specific ML task implemented in a cell is classified in
the left part, returning a task label, e.g. “data preprocessing”
or “model training”. The right part of the process consists
of two actions. First, the code of the cell is tokenized into
its elements (e.g., keywords, operators, identifiers), creating
the cell tokens. Second, in the generate embedding action, the
syntax and the semantic relationships between the tokens
are analyzed and mapped into a vector space, returning a
cell embedding. Finally, the task label and the cell embedding
are composed to a labeled cell embedding.</p>
      </sec>
      <sec id="sec-3-2">
        <title>4.2. Transforming and Loading Cells</title>
        <p>To recommend code from previous Notebooks, the vector
representations and required metadata of code cells must be
stored in a dedicated database called CelRec-DB. A
CelRecDB must fulfill the following requirements:
• Storage space: the value and quality of the
recommendations increase with the amount of available data
for recommendation. Thus, the CelRec-DB must
store the data in a scalable and eficient manner.
• Data retrieval: for recommendations, it is crucial that
the stored data can be accessed quickly. Otherwise,
the value is reduced if recommendations take too
long.
• Data representation: the CelRec-DB has to support
vectors and vector operations, ideally distance
computations.
Pre-Process Cells
Pre-Processed</p>
        <p>Cells</p>
      </sec>
      <sec id="sec-3-3">
        <title>4.3. Recommending K Most Similar Cells</title>
        <p>Given a Notebook containing one query cell, the
recommendation process is depicted in Figure 3. First, the given
Notebook goes through the transform and load process. This
way, the query data is represented the same way, i.e., the
query data is labeled and embedded in the same vector space
as the recommendation data.</p>
        <p>To recommend the k most similar code cells, the
recommendation strategy takes advantage of the labels and the
cell embeddings. First, all labeled cell embeddings in the
database having the same label as the labeled query cell
embedding are filtered to reduce the search space. Second, an
approximate nearest neighbor (k-ANN) search using cosine
similarity is performed to obtain the k most similar labeled
cell embeddings to the labeled query cell embedding. Cosine
similarity was chosen among other distance metrics because
it provides a better-standardized comparability of vectors.
Since the code snippet associated with a labeled cell
embedding is stored as metadata, the associated code snippets of
the k most similar cells are returned as recommendations.</p>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>5. A Framework for the Quantitative</title>
    </sec>
    <sec id="sec-5">
      <title>Evaluation of Cell Recommenders</title>
      <p>After presenting the strategy for generating
recommendations, we present in this section how a framework to
quanti</p>
      <p>Recommend
Notebook with
Query Cell</p>
      <p>Transform &amp;</p>
      <p>Load 
k-ANN</p>
      <p>Search 
&lt;&lt;datastore&gt;&gt;
CelRec-DB</p>
      <p>Top-k Similar
Code Snippets
tatively evaluate the performance of cell recommenders can
be designed. By using this framework, we want to answer
the following evaluation questions (EQ):
EQ1: What is the performance of the top-k cell
recommender?
EQ2: How does its performance vary with increasing lines
of code in a query cell?</p>
      <p>The first question concerns performance in general. The
second question is specific to a developer receiving
recommendations while programming and wanting to write more
lines of code in a cell. This would also show how much code
is needed to obtain relevant recommendations.</p>
      <sec id="sec-5-1">
        <title>5.1. Evaluation Methodology</title>
        <p>
          Code cell recommendation for Notebooks is a special case
of code recommendation. Code recommenders, in general,
usually suggest code for code completion. There are two
main strategies for evaluating code recommenders: partial
code reduction and user studies [
          <xref ref-type="bibr" rid="ref8">8</xref>
          ].
        </p>
        <p>In the former, code snippets are taken, and the last lines
are removed, mimicking that the developer has started
typing code and expects a recommendation. Then, given the
code recommendation, it is checked whether it matches
the removed code. This allows for the analysis of the
recommender’s performance. If this is done regularly, it can
be quickly decided if a recommendation strategy or data
change has had a positive or negative impact.</p>
        <p>User studies, on the other hand, can verify that developers
perceive the recommendations as relevant. However, they
require much time and efort and are dificult to generalize
and replicate.</p>
        <p>Consequently, the partial code reduction evaluation is
more eficient in checking whether a change in the
recommendation strategy improves its performance. For this
reason, we used a partial code reduction strategy with
generated evaluation data consisting of query and
recommendation data. We added noise to the recommendation data to
”confuse“ the recommendation strategy and thereby test its
robustness.</p>
      </sec>
      <sec id="sec-5-2">
        <title>5.2. Evaluation Data</title>
        <p>Before recommendations can be requested, the database
must be filled with recommendation data and query data
for which recommendations will be given.</p>
        <p>The conceptual idea of generating the query and
recommendation datasets is illustrated in Figure 4. In the
following, we will describe the generation process for each dataset
in detail.</p>
        <p>Query Dataset: Since we want developers to receive
recommendations as they type, query cells with diferent
numbers of lines of code per cell should be contained in the
query dataset.
llrsyed sLCO
e g
qu icn
te u
a de
re r
gen yb
Seed Cell
m1
apply mutation operators
m1, m2</p>
        <p>To this end, the generation starts with a set of unique
Notebook code cells S, referred to as seed cells.</p>
        <p>The number of lines in each seed cell is gradually reduced
in the generation process, starting with the last line until
only the first line of code is left. Empty lines are ignored.
Hence, for a seed cell with n lines of code, n query cells are
generated. For each seed cell , the set , consisting of
the seed cells and all generated query cells, is added to the
query dataset QD.</p>
        <p>Recommendation Dataset: Since a top-k cell
recommender suggests the top-k cells that are most similar, the
recommendation dataset must have k recommendation cells
with diferent degrees of similarity for each seed cell.</p>
        <p>The process to generate these recommendation cells has
to ensure that the diferent degrees of similarity conform
to the expected order of the top-k recommendations. To
generate similar recommendation cells from a given seed
cell  ∈ S, mutation operators are applied. Therefore, a set
of k ordered mutation operators {1..} must be defined.
Using these mutation operators, the generation process is
as follows:
• Step 1: apply the mutation operator 1 to the seed
cell .
• Step i, 2 ≤  ≤ : apply the mutation operator 
on the recommendation cell generated in step i-1.</p>
        <p>Since each generation step applies one more mutation
operator on the original seed cell, the similarity of the
generated recommendation cell decreases step by step.</p>
      </sec>
      <sec id="sec-5-3">
        <title>5.3. Assessment of Recommendations</title>
        <p>Our assessment approach is based on the following
hypothesis: a perfect top-k cell recommender recommends the
mutated recommendation cells according to the number of
mutation operators applied. Thus, the first recommendation
would be the recommendation cell with one mutation
operator applied, the second recommendation with two, and so
on.</p>
        <p>Therefore, a recommendation to a query cell is considered
relevant if it results from applying mutation operators to
the original seed cell.</p>
        <p>Metrics are used to evaluate a top-k cell recommender’s
performance. Some metrics use a relevance classification of
the given recommendations. Others use a rating score and a
rating threshold.
recommended</p>
        <p>in top-k
n
relevant / similar</p>
        <p>not relevant / not similar
True Positive (TP)</p>
        <p>False Positive (FP)
False Negative (FN)</p>
        <p>True Negative (TN)
To rate the relevance of a recommendation , a rating
function needs to be defined that maps  to the values of a scale.
This rating scale must specify values for each relevant
(mutated) recommendation and include at least one value for
irrelevant recommendations. The values must be diferent
for each recommendation resulting from a diferent number
of applied mutation operators so that the ranking order of
the recommendations can be considered.</p>
        <p>A top-k cell recommender requires a rating scale with
at least k+1 values where k values are above the rating
threshold.</p>
        <p>The following section describes the selected performance
metrics based on this classification scheme and relevance
rating.</p>
      </sec>
      <sec id="sec-5-4">
        <title>5.4. Selected Performance Metrics</title>
        <p>
          Commonly used metrics for top-k recommender are
precision@k, recall@k, AP@k and nDCG@k [
          <xref ref-type="bibr" rid="ref9">9</xref>
          ]. In this section,
we present the adoption of these metrics to evaluate a top-k
cell recommender.
        </p>
        <p>precision@k: measures how many recommendations
of the top-k positions are relevant. For a query cell  ∈ QD
and the set   consisting of the relevant cells in the
topk recommendations for this query cell, is it calculated as
follows:
@ = | |

recall@k: measures the share of relevant cells that are
also contained in the top-k recommendations. Its value is
calculated as follows:</p>
        <p>| |
|  ∪  |
where the set   ∪   consists of recommendations
considered relevant for the query cell  ∈ QD.</p>
        <p>F1@k: combines the metrics precision@k and recall@k
in one metric and weights them equally. It is calculated this
way:</p>
        <p>@ × @
× @ + @</p>
        <p>AP@k: measures the average of the precision values
at diferent cut-of points in the top-k recommendations.
It evaluates the accuracy of the ranking order of the top-k
recommendations for a query cell  ∈ QD.</p>
        <p>It is calculated as follows:
∑︀
=1 @ × ()
 
where the function () for the
recommendation  at rank  is defined as follows:
() =
{︃1, if () ≥ .</p>
        <p>0, otherwise.</p>
        <p>The rating function () of a recommendation 
has to be defined as described in Section 5.3. If the resulting
rating score is above the defined rating threshold , the
recommendation is considered relevant.</p>
        <p>@ results in the highest score (1) if relevant
recommendations (i.e., the mutations) are ranked higher than
irrelevant recommendations in the top-k positions.
However, the ranking order of the relevant recommendations
does not matter. The score is the lowest (0) if no relevant
recommendations are shown in the top-k positions.</p>
        <p>nDCG@k: In addition to the AP@k, the Normalized
Discounted Cumulative Gain also evaluates the ranking order
of the recommendations based on a non-binary relevance
rating. This also enables an evaluation of the ranking order
of the relevant recommendations (i.e., recommendations 
with () ≥ ).</p>
        <p>Given a list of recommendations  for a query cell  ∈
QD, DCG is calculated based on the defined rating function
() for each recommendation  ∈  for a rank
 ∈ [1, ..., || = ] as follows:</p>
        <p>@ = ∑︁ 2() − 1</p>
        <p>2( + 1)
=1</p>
        <p>Each DCG@k value per query cell is normalized. This
allows us to compare the accuracy between diferent
recommenders, even returning recommendation lists of diferent
lengths:
where   @ represents the DCG for an
optimal recommendation list + for the query cell  ∈ QD. +
is created from  with a permutation  that reorders the
recommendations  ∈  such that they are in a descending
ranking order based on their assigned rating () for
the query cell .</p>
        <p>@ results in the highest score (1) for a query
cell  if the recommendations are in the ranking order of
their relevance based on the assigned ratings.</p>
        <p>Mean: Let M = {precision@k, recall@k, AP@k,
nDCG@k } be the set of the selected performance
metrics. This metric computes the overall mean for each used
performance metric  ∈ M for a given set of query cells
 ⊆ QD as follows:
1</p>
        <p>∑︁ @
|| ∈</p>
      </sec>
      <sec id="sec-5-5">
        <title>5.5. Procedure</title>
        <p>To calculate and present these metrics, the following steps
are performed, given a set S of seed cells:
1. Generate the query dataset QD and the recommendation
dataset based on S.
2. For each query cell  ∈ QD:
a) Request recommendations for .
b) Classify the recommendations according to the
classification rules.</p>
        <p>c) Compute all metrics  ∈ M for .
3. For each metric  ∈ M:</p>
        <p>a) Compute @(QD) on all values of .
4. For each seed cell  ∈ S and for each  ∈ M:</p>
        <p>a) Compute @() on all values of .</p>
        <p>5. Create the performance report.</p>
      </sec>
    </sec>
    <sec id="sec-6">
      <title>6. Implementing the Strategy and the Evaluation Framework</title>
      <p>To demonstrate the application of the evaluation framework
to a top-k cell recommender, we developed JupyRecSys,
implementing the cell recommendation strategy presented in
Section 4 and the CelRecEval tool to automate the
presented evaluation framework. The implementations and
adjustments to the recommendation strategy and the
evaluation framework are described below.</p>
      <sec id="sec-6-1">
        <title>6.1. JupyRecSys - A Top-3 Cell</title>
      </sec>
      <sec id="sec-6-2">
        <title>Recommender</title>
        <p>The top-3 cell recommender JupyRecSys is implemented
as a Python library, which is integrated into a JupyterLab
extension. It consists of a back- and frontend; its user
interface is shown in Figure 6. The backend provides REST
endpoints to upload Notebooks to the CelRec-DB or to request
recommendations. To access the CelRec-DB, a dedicated
database service is provided, which ofers all most often
needed queries to facilitate the search for similar cells.</p>
        <p>
          We used existing tools and technologies to implement
some steps in the recommendation strategy. To implement
the embedd cell process, we applied our cell labeling tool
JupyLabel [
          <xref ref-type="bibr" rid="ref10">10</xref>
          ] to get the cell’s task label. Further, we used
the pre-trained CodeBERT model [
          <xref ref-type="bibr" rid="ref11">11</xref>
          ] to analyze the cell
tokens and map them into a vector space in the
implementation of the generate embedding action. Finally, we used the
specialized vector database Milvus DB [
          <xref ref-type="bibr" rid="ref12">12</xref>
          ] to set up the
CelRec-DB and applied its optimized k-ANN search method
that supports cosine similarity as a standard feature.
        </p>
        <p>CelRecEval implements the cell relevance classification
rules based on the presented confusion matrix (Section 5.3).
As relevance rating, the following scores are assigned to the
top-3 recommendations, based on how the recommendation
is related to the original seed cell of the query cell: 5 (M1
applied), 4 (M1 &amp; M2 applied), 3 (M1, M2 &amp; M3 applied) and 1
(not related to query cell). Consequently, the used relevance
threshold is  = 3. Further, CelRecEval implements the
selected performance metrics accordingly.</p>
        <p>The parameters must be changed to apply CelRecEval to
other top-k cell recommenders. Further, the mutation
operators and the REST endpoints for uploading query and
recommendation data and requesting recommendations must
be adapted accordingly. If a diferent CelRec-DB is used, an
adapter for deleting the data has to be provided since each
evaluation has to start with an empty database.</p>
      </sec>
    </sec>
    <sec id="sec-7">
      <title>7. Evaluation</title>
      <sec id="sec-7-1">
        <title>6.2. CelRecEval - A Cell Recommender</title>
      </sec>
      <sec id="sec-7-2">
        <title>Evaluation Tool</title>
        <p>CelRecEval implements the cell recommender evaluation
framework, especially for JupyRecSys. It is provided as
a Python CL-tool, allowing the user to configure various
parameters such as the number of recommended cells
(topk), the number of recommended cells per seed cell, or the
metric selection. In addition, the report’s output format, e.g.,
an Excel spreadsheet, can be configured.</p>
        <p>As the generation of the evaluation data depends on the
cell recommender’s k-value and we wanted to evaluate the
top-3 cell recommender JupyRecSys, three mutation
operators for the generation of the recommendation data are
implemented:</p>
        <p>M1: Only the variable names are changed. This is a
common case when rewriting similar code.</p>
        <p>M2: The variable names are changed, and comment lines
separate the lines of the query cell. This case is
especially interesting for recommendation strategies,
which also consider comments.</p>
        <p>M3: The variable names are changed, comment lines
separate the lines of the query cell, and the code lines
of the query cell are duplicated and inverted.</p>
        <p>The resulting cell mutations, especially the ones
generated by the M3 oerator, which introduces a lot of noise by
generating nonsense code, allow us to make statements
about the robustness of the recommendation strategy.</p>
        <p>The following code illustrates the application of the
mutation operators on an example seed cell:
1 lr = LogisticRegression()
2 lr.fit(X_train,y_train)</p>
        <p>Listing 1: Example seed cell</p>
        <p>After applying all three mutation operators, the following
code cell is generated as one of the recommendation cells:
1 new_lr = new_LogisticRegression()
2 noissergeRcitsigoL_wen = rl_wen
3 # Additional comment line
4 new_lr.fit(new_X_train, new_y_train)
5 )niart_y_wen ,niart_X_wen(tif.rl_wen</p>
        <p>Listing 2: Recommendation cell with M1-M3 applied</p>
        <p>
          For the evaluation, we selected 114 unique seed cells from
the Notebooks provided by KGTorrent [
          <xref ref-type="bibr" rid="ref13">13</xref>
          ]. Using
CelRecEval, a query dataset with 810 cells and a recommendation
dataset with 342 cells were generated. The 810
recommendation lists returned by JupyRecSys were evaluated, and
the performance report was generated. Two sets of mean
performance scores (MPS) were calculated:
MPS1: All query cells’ mean scores of all performance
metrics  ∈ M were computed.
        </p>
        <p>@(QD)
MPS2: For each seed cell  ∈ S, the mean performance
scores of all performance metrics  ∈ M for all its
generated query cells () were computed.</p>
        <p>∀ ∈ S : @()</p>
        <p>This way, we can gain insights into the overall
performance, analyze performance across diferent code cell types,
and identify dificulties with specific seed cells.</p>
        <p>In the following, we interpret the obtained performance
metric scores according to the evaluation questions EQ1 and
EQ2 presented in Section 5.</p>
      </sec>
      <sec id="sec-7-3">
        <title>7.1. EQ1: Performance of the</title>
      </sec>
      <sec id="sec-7-4">
        <title>Recommendation Strategy</title>
        <sec id="sec-7-4-1">
          <title>MPS1: Mean Performance Scores</title>
          <p>recall@3 F1@3
0.8697 0.8697
not always included in the recommendation lists. By
analyzing the MPS2 scores (see Table 7.2), we observe that the
following cell characteristics negatively impact the
recommendation strategy’s performance :
• For-loops: The three seed cells with the lowest
precision@3, recall@3 and F1@3 scores are the cells
76, 4, and 40. All three cells contain a for-loop
with data operations. In particular, if a query cell
only contains the first line of a for-loop, this leads
to matches with all cells that contain a for-loop, as
these usually only difer in the variable names.
• Multiple tasks: Seed cell 8 achieved only
moderate results. A closer look revealed that this cell
implements multiple tasks: dependency import, model
prediction, and model evaluation. Considering only
the first few code lines, the recommender suggests
other dependency import code cells.
• Many code lines: It could be observed that the
strategy’s performance is lower for seed cells having
many lines of code, e.g., 4 = 12.</p>
        </sec>
      </sec>
      <sec id="sec-7-5">
        <title>7.2. EQ2: Impact of SLOCs to Performance</title>
      </sec>
      <sec id="sec-7-6">
        <title>Scores</title>
        <p>If a seed cell contains precisely one code line, one query cell
and three mutated recommendation cells are created. For
this query cell, the recommendations given are perfect, and
the performance scores are optimal. This was the case for
14 out of 114 seed cells.</p>
        <p>Our analysis of the performance results indicates a
significant correlation between the number of code lines and
the strategy’s performance. The generated query cells,
having fewer lines than their common seed cell, sometimes
exhibit higher similarity with recommendation cells with
similar numbers of lines instead of the recommendation
cells that would ultimately be relevant to the developer.
This phenomenon can lead to erroneous recommendations,
lowering the average metric result for the specific seed cell.
Therefore, it can be concluded that the more lines a
developer enters, the more accurate the recommendations will
become.</p>
        <p>Nevertheless, even the lowest-performing seed cell
achieves an nDCG@3 value of at least 0.5, indicating that
approximately half of the relevant recommendations are
still recommended in the correct ranking order within the
top-3 ranks.</p>
      </sec>
    </sec>
    <sec id="sec-8">
      <title>8. Discussion</title>
      <p>In response to research question RQ1, we proposed a cell
recommendation strategy, which we implemented in the
JupyterLab extension JupyRecSys. The transformation of
code cells into a semantic vector space enables the eficient
computation of similarities between a query cell and a large
number of recommendation cells. Applying an automatic
cell task classifier could further reduce the search space
within the semantic vector space. The evaluation results
in Section 7 highlight the efectiveness of the proposed cell
recommendation strategy.</p>
      <p>To answer RQ2, we designed and implemented an
evaluation framework in the CL-tool CelRecEval.</p>
      <p>We could have generated the evaluation data with
identical query-recommendation pairs. However, this would
have only shown that the similarity calculation works and
would be a rather simplistic evaluation for a top-k cell
recommender, where ranking also plays a role. This would not
reflect real-world usage.</p>
      <p>In practice, developers would receive recommendations
as they type rather than when they have finished writing
a code cell. By introducing cells with diferent numbers of
lines of code and using mutation operators, we were able
to identify weaknesses such as for-loops, multiple tasks, and
many lines of code. Without automated evaluation, it would
have been necessary to manually check all query cells to
identify these issues.</p>
      <p>Furthermore, CelRecEval can be re-executed with the
same setup so that we can evaluate in the future whether
changes to the implemented recommendation strategy
eliminate the weaknesses mentioned above.</p>
      <p>Consequently, CelRecEval enables developers to identify
the strengths and weaknesses of cell recommenders and
compare diferent ones.</p>
    </sec>
    <sec id="sec-9">
      <title>9. Threats to Validity</title>
      <sec id="sec-9-1">
        <title>Internal Validity</title>
        <p>In this paper, we automatically evaluated the performance
of a cell recommendation strategy using our definition of
relevancy of a recommendation. When evaluating
recommenders, users usually evaluate a recommendation’s
relevancy in a so-called online evaluation. However, the impact
of this threat should be limited, as we consider the code’s
similarity and the performed task implemented in a cell as
criteria for recommendation.</p>
      </sec>
      <sec id="sec-9-2">
        <title>External Validity</title>
        <p>The evaluation framework can be adapted with minor
adjustments to other top-k cell recommenders. It allows the
automatic generation of evaluation data suitable for the selected
k. Currently, the evaluation performance results are used
to compare diferent versions of JupyRecSys against each
other. Diferent values for k and diferent sets of mutation
operators may hinder comparability among recommenders.
10. Conclusion and Future Work
This paper has two main contributions. First, we present a
strategy for Jupyter Notebook code cell recommendation.</p>
        <p>MPS2: Mean Performance Scores for selected Seed Cells (sorted by nDCG@3)
SLOC precision@3 recall@3 F1@3 AP@3
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
... ... ... ... ...
6 0.7143 0.7143 0.7143 0.7143
... ... ... ... ...
20 0.5333 0.5333 0.5333 0.7833
12 0.5385 0.5385 0.5385 0.7436
2 0.6667 0.6667 0.6667 0.75
Second, we present a framework for automatically
evaluating such cell recommenders. The framework allows users
to customize the generation of evaluation data, select
performance metrics, and access external tools, such as the cell
recommender or its database. Both the recommendation
strategy and the evaluation framework are implemented as
tools: the strategy as the JupyterLab extension
JupyRecSys cell recommender and the evaluation framework as the
Python CL-tool CelRecEval.</p>
        <p>To demonstrate the application of CelRecEval to a cell
recommender, the framework was adapted to JupyRecSys.</p>
        <p>The evaluation results demonstrate that JupyRecSys exhibits
high performance across all metrics, efectively delivering
relevant code cells in a near-optimal order as the developer
types code into the cell. Given its high metric scores, it is
particularly well-suited to enhancing the reusability of
Notebooks. In addition to evaluating general performance, we
can also make statements about how the cell recommender
performs while a developer is typing into a code cell.
Further, CelRecEval allows us to identify some strengths and
weaknesses of JupyRecSys.</p>
        <p>As part of our future research, we aim to extend
CelRecEval with more performance evaluation metrics to consider
more recommender quality attributes, such as diversity or
confidence.</p>
        <p>Furthermore, the recommendation strategy of
JupyRecSys could be improved by including Markdown text in the
similarity analysis. An online evaluation would give a more
accurate picture of the performance of the cell recommender,
as users would evaluate the relevance of the
recommendations in a real-world setting. A user study with developers
could also provide essential insights into the usability of
this recommender.</p>
        <p>
          All software artifacts, including JupyRecSys, CelRecEval
and the evaluation data are available on Zenodo [
          <xref ref-type="bibr" rid="ref14">14</xref>
          ].
        </p>
      </sec>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>N.</given-names>
            <surname>Ritta</surname>
          </string-name>
          ,
          <string-name>
            <given-names>T.</given-names>
            <surname>Settewong</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R. G.</given-names>
            <surname>Kula</surname>
          </string-name>
          ,
          <string-name>
            <given-names>C.</given-names>
            <surname>Ragkhitwetsagul</surname>
          </string-name>
          ,
          <string-name>
            <given-names>T.</given-names>
            <surname>Sunetnanta</surname>
          </string-name>
          ,
          <string-name>
            <given-names>K.</given-names>
            <surname>Matsumoto</surname>
          </string-name>
          , Reusing My Own Code:
          <article-title>Preliminary Results for Competitive Coding in Jupyter Notebooks</article-title>
          ,
          <source>in: 2022 29th Asia-Pacific Software Engineering Conference (APSEC)</source>
          ,
          <year>2022</year>
          , pp.
          <fpage>457</fpage>
          -
          <lpage>461</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>M.</given-names>
            <surname>Källén</surname>
          </string-name>
          , T. Wrigstad, Jupyter Notebooks on GitHub: Characteristics and
          <string-name>
            <given-names>Code</given-names>
            <surname>Clones</surname>
          </string-name>
          ,
          <source>The Art, Science, and Engineering of Programming</source>
          <volume>5</volume>
          (
          <year>2021</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>J. F.</given-names>
            <surname>Pimentel</surname>
          </string-name>
          ,
          <string-name>
            <given-names>L.</given-names>
            <surname>Murta</surname>
          </string-name>
          ,
          <string-name>
            <given-names>V.</given-names>
            <surname>Braganholo</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Freire</surname>
          </string-name>
          ,
          <article-title>Understanding and Improving the Quality and Reproducibility of Jupyter Notebooks</article-title>
          ,
          <source>Empirical Software Engineering</source>
          <volume>26</volume>
          (
          <year>2021</year>
          )
          <fpage>65</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>A.</given-names>
            <surname>Rule</surname>
          </string-name>
          ,
          <string-name>
            <surname>I. Drosos</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Tabard</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J. D.</given-names>
            <surname>Hollan</surname>
          </string-name>
          ,
          <article-title>Aiding Collaborative Reuse of Computational Notebooks with Annotated Cell Folding</article-title>
          ,
          <source>Proc. ACM Hum.-Comput. Interact</source>
          .
          <volume>2</volume>
          (
          <year>2018</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>M.</given-names>
            <surname>Horiuchi</surname>
          </string-name>
          ,
          <string-name>
            <given-names>Y.</given-names>
            <surname>Sasaki</surname>
          </string-name>
          ,
          <string-name>
            <given-names>C.</given-names>
            <surname>Xiao</surname>
          </string-name>
          , M. Onizuka,
          <article-title>JupySim: Jupyter Notebook Similarity Search System</article-title>
          .,
          <source>in: EDBT</source>
          ,
          <year>2022</year>
          , pp.
          <fpage>2</fpage>
          -
          <lpage>554</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <given-names>Elyra</given-names>
            <surname>Team</surname>
          </string-name>
          ,
          <source>Code Snippets - Elyra 3.15</source>
          .0 documentation, https://elyra.readthedocs.
          <source>io/en/v3.15</source>
          .0/user_ guide/code-snippets.html,
          <year>2022</year>
          . [Acc.
          <fpage>19</fpage>
          -Sep-2024].
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <given-names>C.</given-names>
            <surname>Ragkhitwetsagul</surname>
          </string-name>
          ,
          <string-name>
            <given-names>V.</given-names>
            <surname>Prasertpol</surname>
          </string-name>
          ,
          <string-name>
            <given-names>N.</given-names>
            <surname>Ritta</surname>
          </string-name>
          , P. SaeWong, T. Noraset,
          <string-name>
            <given-names>M.</given-names>
            <surname>Choetkiertikul</surname>
          </string-name>
          ,
          <source>Typhon: Automatic Recommendation of Relevant Code Cells in Jupyter Notebooks</source>
          ,
          <year>2024</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [8]
          <string-name>
            <given-names>S.</given-names>
            <surname>Proksch</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Amann</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Nadi</surname>
          </string-name>
          ,
          <string-name>
            <surname>M.</surname>
          </string-name>
          <article-title>Mezini, Evaluating the evaluations of code recommender systems: A reality check</article-title>
          ,
          <source>in: 2016 31st IEEE/ACM International Conference on Automated Software Engineering (ASE)</source>
          ,
          <year>2016</year>
          , pp.
          <fpage>111</fpage>
          -
          <lpage>121</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          [9]
          <string-name>
            <given-names>Y</given-names>
            <surname>.-M. Tamm</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R.</given-names>
            <surname>Damdinov</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Vasilev</surname>
          </string-name>
          ,
          <article-title>Quality Metrics in Recommender Systems: Do We Calculate Metrics Consistently?</article-title>
          ,
          <source>in: Proceedings of the 15th ACM Conference on Recommender Systems</source>
          , RecSys '21,
          <string-name>
            <surname>Association</surname>
          </string-name>
          for Computing Machinery, New York, NY, USA,
          <year>2021</year>
          , p.
          <fpage>708</fpage>
          -
          <lpage>713</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          [10]
          <string-name>
            <given-names>M.</given-names>
            <surname>Perez</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Aydin</surname>
          </string-name>
          ,
          <string-name>
            <given-names>H.</given-names>
            <surname>Lichter</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A Flexible</given-names>
            <surname>Cell</surname>
          </string-name>
          <article-title>Classification for ML Projects in Jupyter Notebooks</article-title>
          ,
          <year>2024</year>
          . URL: https://arxiv.org/abs/2403.07562. arXiv:
          <volume>2403</volume>
          .
          <fpage>07562</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          [11]
          <string-name>
            <given-names>Z.</given-names>
            <surname>Feng</surname>
          </string-name>
          ,
          <string-name>
            <given-names>D.</given-names>
            <surname>Guo</surname>
          </string-name>
          ,
          <string-name>
            <given-names>D.</given-names>
            <surname>Tang</surname>
          </string-name>
          ,
          <string-name>
            <given-names>N.</given-names>
            <surname>Duan</surname>
          </string-name>
          ,
          <string-name>
            <given-names>X.</given-names>
            <surname>Feng</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Gong</surname>
          </string-name>
          ,
          <string-name>
            <given-names>L.</given-names>
            <surname>Shou</surname>
          </string-name>
          ,
          <string-name>
            <given-names>B.</given-names>
            <surname>Qin</surname>
          </string-name>
          , T. Liu,
          <string-name>
            <given-names>D.</given-names>
            <surname>Jiang</surname>
          </string-name>
          ,
          <string-name>
            <surname>M.</surname>
          </string-name>
          <article-title>Zhou, CodeBERT: A Pre-Trained Model for Programming</article-title>
          and
          <source>Natural Languages</source>
          ,
          <year>2020</year>
          . URL: https://arxiv.org/abs/
          <year>2002</year>
          .08155. arXiv:
          <year>2002</year>
          .08155.
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          [12]
          <article-title>Milvus, The High-Performance Vector Database Built for Scale</article-title>
          , https://milvus.io/,
          <year>2024</year>
          . [Acc.
          <fpage>13</fpage>
          -Sep-2024].
        </mixed-citation>
      </ref>
      <ref id="ref13">
        <mixed-citation>
          [13]
          <string-name>
            <given-names>L.</given-names>
            <surname>Quaranta</surname>
          </string-name>
          ,
          <string-name>
            <given-names>F.</given-names>
            <surname>Calefato</surname>
          </string-name>
          ,
          <string-name>
            <given-names>F.</given-names>
            <surname>Lanubile</surname>
          </string-name>
          ,
          <article-title>KGTorrent: A Dataset of Python Jupyter Notebooks from Kaggle</article-title>
          ,
          <source>in: 2021 IEEE/ACM 18th International Conference on Mining Software Repositories (MSR)</source>
          , IEEE,
          <year>2021</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref14">
        <mixed-citation>
          [14]
          <string-name>
            <given-names>S.</given-names>
            <surname>Aydin</surname>
          </string-name>
          ,
          <string-name>
            <given-names>D.</given-names>
            <surname>Mertens</surname>
          </string-name>
          ,
          <string-name>
            <given-names>O.</given-names>
            <surname>Xu</surname>
          </string-name>
          ,
          <source>Zenodo: An Automated Evaluation Approach for Jupyter Notebook Code Cell Recommender Systems - Software Artifacts</source>
          , https:// doi.org/10.5281/zenodo.13836922,
          <year>2024</year>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>